I wanted to say that I did the same implementation as above, but I ran into this strange error and hit my head around and fixed this error 'cannot modify NodeName of Null' , so finally I fixed the error today and I wanted to to share it, so people donβt have to look for it anymore, which could be a mistake. I know this is an old post apologizing for this.
- get the github code (directive). link below. thanks @Abhijith Nagaraja for the post.
https://github.com/Abhijith-Nagaraja/tinymce-docs/blob/master/integrations/angular2.md#sample-directive-implementation-with-ngmodel-two-way-binding
2. add two variables to the directive
private editor; private init: boolean = false;
rewrite method
writeValue(value: any): void {
to
writeValue(value: any): void { // This check is necessary because, this method gets called before editor gets initialised. // Hence undefined/null pointer exceptions gets thrown if (this.init) { if (tinymce.get(this.selector)) { tinymce.get(this.selector).setContent(value, {format: 'raw'}); } } }
replace in ValueOnChange(change: boolean) this.val = tinymce.activeEditor.getContent();
to
if (tinymce.activeEditor) { this.val = tinymce.activeEditor.getContent(); }
rewrite tinymce.init(options)
to
tinymce.init(options).then(() => { this.init = true; });
and the last add the ngOnDestroy method
ngOnDestroy() { tinymce.remove(this.editor); }
This fixed a bug for me and also fixed for me when the editor was already initialized and I reused it, it will not compile. but now because of ngOnDestroy I can now destroy the editor, and afterViewInit will remember tinymce.init
source share