Ledzz / angular2-tinymce

Angular 2 component for TinyMCE MCE WYSIWYG editor
https://angular2-tinymce.surge.sh
66 stars 37 forks source link

tinymce.editor in undefined in AfterViewInit #68

Closed exsoflowe closed 5 years ago

exsoflowe commented 5 years ago

I try to get 'editor' property in AfterViewInit cycle. But I get undefined.

So I use setTimeout. Is it correct?

In my project I use setTimeout 0ms and I get editor instance. But in Stackblitz I need to use setTimeout 1000ms.

What am I doing wrong? Thanks.

Stackblitz example https://stackblitz.com/edit/angular2-tinymce-example-afterviewinit See app.component.ts

Ledzz commented 5 years ago

When you use AfterViewInit, AfterViewInit of tinymce component is not run yet, so the delay is needed. I will ship more events (outputs) soon, so you can rely on them.

exsoflowe commented 5 years ago

Yes. I see in TinymceComponent.prototype.ngAfterViewInit

        if (this.options.baseURL) {
            tinymce.baseURL = this.options.baseURL;
        }
        tinymce.init(this.options);

Thanks!

Or we can use init_instance_callback in ngOnInit

    this.editorRef.options.init_instance_callback = (editor) => {
      editor.on('blur', (event) => {
        this.onBlur.emit(this.editorRef.editor);
      });
    };
Ledzz commented 5 years ago

In version 3.3.0 you can use (init) callback.

<app-tinymce (init)='actionOnInit($event)'></app-tinymce>