This posting is regards [email protected] loaded with [email protected].
Although there are a couple of articles on SO with this question I believe this is still an open question. Please do not mark this posting as a duplicate.
To replicate problem: 1) instantiate a DOM element with the ckeditor directive. 2) navigate away from the view in such a way that the Angular Component that is hosting the ckeditor is destroyed. You get this in the Javascript console:
ckeditor.js:19 [CKEDITOR] Error code: editor-destroy-iframe.
There is a closed bug on github over this with no apparent or acceptable solution, unless I missed it. If there is a solution there we should document it on this post because it is incomplete or obscure.
The problem is apparently that Angular framework destroys the iframe element before the ckeditor itself is destroyed. This causes the diagnostic message.
One proposed solution involves the use of a plugin called divarea. From what I understand this replaces the iframe with a div element. The reason this is problematic is that the CSS elements from the hosting page will be mixed in with the CSS that CKEDITOR uses.
Another proposed solution involves the following snippet of code:
for (name in CKEDITOR.instances) {
CKEDITOR.instances[name].destroy(true);
}
This SO posting mentions this and asks for where this code can be inserted. There is no Angular lifecycle event that seems to work. Even if it did this would not be an acceptable fix because it destroys all CKEDITOR instances and in my application there might be more than one on the page that might survive a router event.
Along those lines I discovered that I can find "my" CKEDITOR instance in my Angular Component with these steps. In the template:
<ckeditor id="content"
#editor
[(ngModel)]="editorContent"
[config]="{}"
debounce="500"
name="content"
></ckeditor>
Which is standard except for the #editor directive which establishes a local variable. Then in the component you can build a method like this:
declare const CKEDITOR: any;
@Component() ....
@ViewChild('editor') ckeditor: CKEditorComponent;
destroyEditor() {
var name = this.ckeditor.instance.name;
CKEDITOR.instances[name].destroy(true);
}
So the question is: where to call the destroyEditor function? (Other question is whether the destroy(true) method is the right one to call.)
Calling it from ngOnDestroy does not work. Catching an event from the router hasn't worked either. Any other suggestions?