Skip to content

Commit

Permalink
Fix cannot read property 'destroy' of undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
kzimny committed Dec 15, 2020
1 parent 6da1f1d commit 0e44a24
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ckeditor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class CKEditorComponent implements OnChanges, AfterViewInit, OnDestroy {
_value = '';
instance: any;
debounceTimeout: any;
private destroyed = false;

/**
* Constructor
Expand Down Expand Up @@ -87,10 +88,10 @@ export class CKEditorComponent implements OnChanges, AfterViewInit, OnDestroy {
* On component destroy
*/
ngOnDestroy() {
this.destroyed = true;
this.zone.runOutsideAngular( () => {
if (this.instance) {
CKEDITOR.removeAllListeners();
CKEDITOR.instances[this.instance.name].destroy();
this.instance.destroy();
this.instance = null;
}
Expand All @@ -101,6 +102,9 @@ export class CKEditorComponent implements OnChanges, AfterViewInit, OnDestroy {
* On component view init
*/
ngAfterViewInit() {
if (this.destroyed) {
return;
}
this.ckeditorInit(this.config || {});
}

Expand Down

0 comments on commit 0e44a24

Please sign in to comment.