Angular4中如何使用CKEditor?

How to use CKEditor in Angular 4?

  1. 我使用 npm install ng2-ckeditor 这个命令安装 CKEditor。
  2. 然后在我的index.html
  3. 中添加ckeditor.js
  4. 然后在app.module.ts
  5. 中导入import { CKEditorModule } from 'ng2-ckeditor';
  6. 然后在我的HTML页面使用CKEditor

     <ckeditor ngModel="{{ckeditorContent}}" formControlName="circular_contents" [config]="{uiColor: '#99000'}" [readonly]="false" debounce="500" debounce="500">
     </ckeditor>
    
  7. 当时我得到错误ERROR TypeError: Cannot set property 'dir' of undefined

现在如何在我的 HTML 页面中使用 CKEditor。

一切正常只是在您的 index.html 页面中包含 ckeditor cdn link,不要下载 ckeditor.js.

<script src="https://cdn.ckeditor.com/4.5.11/full/ckeditor.js"></script>

由于您正在使用 angular 4,因此请将 ngModel 的语法更改为 [(ngModel)].

像这样:

<ckeditor [(ngModel)]="templateConversionDTO.htmlContent"
                name="myckeditor" required debounce="500"> </ckeditor>

并且不要忘记在您的 Index.html 文件中添加 Ckeditor 的 CDN,这很重要。

<script src="https://cdn.ckeditor.com/4.6.1/full/ckeditor.js"></script>