我在尝试分别添加 CKEditor 和插件时遇到了这个问题。
最简单的方法是转到CKEditor Online Builder 并选择您需要的插件和工具栏项目,然后在五个步骤后生成您需要使用的代码。
然后你可以使用 build 文件夹中名为 ckeditor.js 的文件,这几乎就是你所需要的。
1- 添加CKEditorModule
@NgModule({
imports: [CKEditorModule],
...
}
2- 将 CKEditor 标签添加到您的模板中
<ckeditor
[editor]="Editor"
[(ngModel)]="notification.body"
(ready)="onReady($event)"
[config]="config"
></ckeditor>
3- 在您的组件中导入自定义的 CKEditor js 文件(您应该从下载的自定义 CKEditor 的 build 文件夹中复制该文件)
import * as customEditor from './ckeditor';
4- 在你的组件中创建一个属性
public Editor = customEditor;
5- 添加你的配置
ngOnInit() {
this.config = {
toolbar: {
items: [
'heading',
'|',
'fontSize',
'fontFamily',
'|',
'bold',
'italic',
'underline',
'strikethrough',
'highlight',
'|',
'alignment',
'|',
'numberedList',
'bulletedList',
'|',
'indent',
'outdent',
'|',
'todoList',
'link',
'blockQuote',
'imageUpload',
'insertTable',
'|',
'undo',
'redo'
]
},
language: 'en',
image: {
toolbar: [
'imageTextAlternative',
'imageStyle:full',
'imageStyle:side'
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells'
]
},
licenseKey: '',
wordCount: {
onUpdate: stats => {
this.charactersLength = stats.characters
}
}
}
}
就是这样:)