Skip to content

Commit

Permalink
Fix the problem on destroy happening to fast
Browse files Browse the repository at this point in the history
The problem  is visible in ckeditor#110
  • Loading branch information
bhugot authored Jun 4, 2020
1 parent fe81ede commit 8952b97
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ckeditor/ckeditor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue
onTouched?: () => void;

private _data: string = null;

/**
* If the component passed in ngOnDestroy to avoid the
* execution of the getEditorNamespace promise.
*/
private _destroyed = false;
/**
* CKEditor 4 script url address. Script will be loaded only if CKEDITOR namespace is missing.
*
Expand All @@ -251,11 +255,15 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue

ngAfterViewInit(): void {
getEditorNamespace( this.editorUrl ).then( () => {
if( this._destroyed ){
return;
}
this.ngZone.runOutsideAngular( this.createEditor.bind( this ) );
} ).catch( window.console.error );
}

ngOnDestroy(): void {
this._destroyed = true;
this.ngZone.runOutsideAngular( () => {
if ( this.instance ) {
this.instance.destroy();
Expand Down

0 comments on commit 8952b97

Please sign in to comment.