javascript - 在 Angular 2 中使用 CKEditor 的自定义配置文件

标签 javascript ckeditor angular2-template ckeditor4.x

我想在 Angular 2 中使用我自己的 CKEditor 配置文件。

执行此操作时

 CKEDITOR.replace('editor', {
            customConfig: '../../admin/app/js/scripts/ck-editor-config.js',
            extraPlugins: 'colorbutton,colordialog,embed'
});

CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR;

但是我如何在我的组件中获取 CKEDITOR 的实例?

我已经在我的 Angular 2 项目中集成了 CKEditor,但我想更改配置文件,我想添加我自己的自定义配置。请建议我可以做什么?我没有 CKEditor 的实例。

最佳答案

经过多次探索,我明白了:

在 HTML 中使用:

  <div>
       <ckeditor 
                 formControlName="contentBody" 
                 [(ngModel)]="content.contentBody" 
                 [config]="{uiColor: ''}" 
                 [readonly]="false" 
                 debounce="500">
       </ckeditor>
  </div>

将以下代码行添加到您正在使用此CKEditor组件中。

CKEditorModuleCKEditorComponent 导入到您的组件中:

import { CKEditorModule, CKEditorComponent } from 'ng2-ckeditor';

创建默认内容:

  this.ckeditorContent = `<p>My HTML</p>`;

现在您可以在组件中的ngAfterViewChecked() Hook 中编写CKEditor的配置:

  ngAfterViewChecked() {

    if (this.contentForm.value.type == 'Html') {


      let editor = this.ckEditor.instance;

      editor.config.height = 200;

      // editor.config.toolbar = [
      //   // { name: 'document', items: ['Source', 'Templates'] },
      //   { name: 'colors', items: ['TextColor', 'BGColor'] }, '/',
      //   { name: 'insert', items: ['Image'] },
      //   { name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] },
      //   // { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat'] }
      // ]

      editor.config.toolbar =[
          ['Source', '-', 'Bold', 'Italic']
        ];

      editor.config.removeButtons = 'Templates,Find,Replace,Scayt,SelectAll,Form,Radio';

      editor.config.removePlugins = 'elementspath,save,font,Undo,Redo';


    }

  }

关于javascript - 在 Angular 2 中使用 CKEditor 的自定义配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47990417/

相关文章:

javascript - 如何检查插件的功能是否存在?

asp.net - 无法加载类型 'CKFinder.Connector.Connector'

html - 如何在angular2中加载图像

angularjs - Angular2 TemplateRef 选择器

javascript - 为什么在用作选择器的类或 ID 已从 HTML 中删除后仍会调用 jQuery 函数?

javascript - 如何使用 React 教程修复 Meteor 中的 eslint 错误

javascript - 如何防止滚动绑定(bind)到同一容器的其他元素?

javascript - PrimeFaces 扩展 CKEditor : cannot access custom config

javascript - CKEDITOR,在 CKEDITOR 之外调用 FullScreen Action

javascript - 根据变量angular生成动态css