相关疑难解决方法(0)

Angular,ng-ckeditor和editor-destroy-iframe错误

此帖子是关于ng2-ckeditor@1.1.13和ckeditor@4.8.0一起加载的。

尽管有几篇有关SO的文章,但我相信这仍然是一个悬而未决的问题。请不要将此帖子标记为重复。

复制问题:1)使用ckeditor指令实例化DOM元素。2)导航离开视图,以致破坏托管ckeditor的Angular Component 。您可以在Javascript控制台中获得此信息:

ckeditor.js:19 [CKEDITOR] Error code: editor-destroy-iframe.
Run Code Online (Sandbox Code Playgroud)

github上有一个封闭的bug,没有明显或可接受的解决方案,除非我错过了。如果有解决方案,我们应该在这篇文章中记录它,因为它不完整或模糊。

问题显然是在ckeditor本身销毁之前,Angular框架销毁了iframe元素。这将导致诊断消息。

一种建议的解决方案涉及使用名为divarea的插件。据我了解,这将iframe替换为div元素。这是有问题的,原因是托管页面中的CSS元素将与CKEDITOR使用的CSS混合在一起。

另一个建议的解决方案涉及以下代码片段:

for (name in CKEDITOR.instances) {
    CKEDITOR.instances[name].destroy(true);
}
Run Code Online (Sandbox Code Playgroud)

这样的SO帖子提到了这一点,并要求在哪里可以插入此代码。没有似乎有效的Angular生命周期事件。即使这样做,也不可接受,因为它会破坏所有CKEDITOR实例,并且在我的应用程序中,页面上可能有多个可能幸免于路由器事件。

沿着这些思路,我发现通过这些步骤可以在我的Angular组件中找到“我的” CKEDITOR实例。在模板中:

  <ckeditor id="content"
            #editor
            [(ngModel)]="editorContent"
            [config]="{}"
            debounce="500"
            name="content"
  ></ckeditor>
Run Code Online (Sandbox Code Playgroud)

除了用于建立局部变量的#editor指令以外,这是标准的。然后,您可以在组件中构建如下方法:

declare const CKEDITOR: any;

@Component() ....

  @ViewChild('editor') ckeditor: CKEditorComponent;

  destroyEditor() {
     var name = this.ckeditor.instance.name;
     CKEDITOR.instances[name].destroy(true);
  }
Run Code Online (Sandbox Code Playgroud)

所以问题是:在哪里调用destroyEditor函数?(另一个问题是destroy(true)方法是否是正确的调用方法。)

ngOnDestroy调用它不起作用。从路由器捕获事件也不起作用。还有其他建议吗?

ckeditor angular

5
推荐指数
1
解决办法
1081
查看次数

标签 统计

angular ×1

ckeditor ×1