Skip to content

Commit 1012107

Browse files
bhugotf1ames
authored andcommitted
Fix the problem on destroy happening to fast
The problem is visible in ckeditor#110
1 parent 625074c commit 1012107

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/ckeditor/ckeditor.component.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue
238238
onTouched?: () => void;
239239

240240
private _data: string = null;
241-
241+
/**
242+
* If the component passed in ngOnDestroy to avoid the
243+
* execution of the getEditorNamespace promise.
244+
*/
245+
private _destroyed = false;
242246
/**
243247
* CKEditor 4 script url address. Script will be loaded only if CKEDITOR namespace is missing.
244248
*
@@ -251,11 +255,15 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue
251255

252256
ngAfterViewInit(): void {
253257
getEditorNamespace( this.editorUrl ).then( () => {
258+
if( this._destroyed ){
259+
return;
260+
}
254261
this.ngZone.runOutsideAngular( this.createEditor.bind( this ) );
255262
} ).catch( window.console.error );
256263
}
257264

258265
ngOnDestroy(): void {
266+
this._destroyed = true;
259267
this.ngZone.runOutsideAngular( () => {
260268
if ( this.instance ) {
261269
this.instance.destroy();

0 commit comments

Comments
 (0)