Using tinyMCE with Angular I need to insert text at the cursor position, preferably with a toolbar button.
As I understand, I'll need to use the onExecCommand
event with mceInsertContent
command.
I've looked at the following:
- How to insert text in TinyMCE Editor where the cursor is?
- Inserting text in TinyMCE Editor where the cursor is
But the solutions don't help in this case.
editor-dialog.component.html
<editor [init]="tinyMceConfig"
[formControl]="data.formControl">
</editor>
editor-dialog.component.ts
/* ... */
export class EditorDialogComponent implements OnInit {
tinyMceConfig: any;
constructor(
/* ... */
) { }
ngOnInit() {
this.configureTinyMce();
}
configureTinyMce() {
this.tinyMceConfig = {
theme: 'modern',
menubar: false,
branding: false,
height: 400,
skin_url: 'assets/tinymce/skins/lightgray',
inline: false,
plugins: [
'advlist lists link image directionality',
'searchreplace visualblocks visualchars media table contextmenu paste textcolor colorpicker pagebreak code'
],
// tslint:disable-next-line:max-line-length
toolbar: 'copy undo redo formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat hr pagebreak code',
image_advtab: true,
imagetools_toolbar: 'rotateleft rotateright | flipv fliph | editimage imageoptions',
paste_data_images: !0,
importcss_append: !0,
images_upload_handler: function (e, t, a) {
console.log('image');
t('data:' + e.blob().type + ';base64,' + e.base64());
},
};
}
}
Thanks