this is a angular solution:
import { Component, OnInit, Input, OnDestroy, AfterViewInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { EditorFieldInfo } from '@app/shared/models/editorfieldinfo';
import 'tinymce';
declare let tinymce: any;
@Component({
selector: 'rich-text-field',
templateUrl: './rich-text-field.component.html',
styleUrls: ['./rich-text-field.component.scss']
})
export class RichTextFieldComponent implements OnInit, OnDestroy, AfterViewInit {
formControl: FormControl;
editor: any;
@Input()
formGroup: FormGroup;
@Input()
fieldDefinition: EditorFieldInfo;
constructor() {
this.fieldDefinition = { name: '??', description:'', placeholder:'', hint:'', fieldtype:'', length:0, defaultValue:'', listValues: null};
}
ngOnInit(): void
{
this.formControl = <FormControl> this.formGroup.get(this.fieldDefinition.name);
}
ngAfterViewInit() {
tinymce.init({
base_url: '/tinymce',
suffix: '.min',
selector: '#mce-' + this.fieldDefinition.name,
toolbar: 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | outdent indent',
menubar: 'edit insert format table tools', branding: false, placeholder: '',
external_plugins: {'placeholder': '/assets/scripts/placeholder.min.js'},
content_style: 'body {font-weight: 400;line-height:1.125;font-family:RO Sans,Calibri,sans-serif;letter-spacing:normal;}',
setup: editor => {
this.editor = editor;
}
});
}
ngOnDestroy() {
tinymce.remove(this.editor);
}
}