1、官网下载Ckeditor
ck5最新版本不会用,目前是用的是ck4,下载full package全包,这样功能比较全。
官网地址:https://ckeditor.com/ckeditor-4/download/
https://ckeditor.com/docs/ckeditor4/latest/api/index.html
2、下载解压后,把ckeditor文件夹拷贝到项目中。我放在asset文件夹下
3、index.html
引用js:
<script type="text/javascript" src="assets/ckeditor/ckeditor.js" charset="UTF-8"></script>
4、声明全局变量
src文件夹新建typings.d.ts文件
declare var CKEDITOR: any;
5、使用
画面加载时候配置CK
private initConfig() { this.editor = CKEDITOR.replace('editor'); // 界面语言,默认为 'en' this.editor.config.language = 'zh-cn'; // 样式 // this.editor.config.uiColor = '#66AB16'; // 工具栏(基础'Basic'、全能'Full'、自定义)plugins/toolbar/plugin.js this.editor.config.toolbar = 'Basic'; //工具栏是否可以被收缩 this.editor.config.toolbarCanCollapse = true; //工具栏的位置 this.editor.config.toolbarLocation = 'top'; //可选:bottom //工具栏默认是否展开 this.editor.config.toolbarStartupExpanded = true; //设置HTML文档类型 // this.editor.config.docType = // '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd%22'; //是否使用HTML实体进行输出 plugins/entities/plugin.js this.editor.config.entities = true; // //是否使用完整的html编辑模式 如使用,其源码将包含:<html><body></body></html>等标签 // this.editor.config.fullPage = true; // //是否忽略段落中的空字符 若不忽略 则字符将以“”表示 plugins/wysiwygarea/plugin.js // this.editor.config.ignoreEmptyParagraph = true; // this.editor.config.extraPlugins = [extraPlugins]; // this.editor.config.filebrowserImageBrowseUrl = 'http://192.168.11.10:8080/api/new_pic?id=1'; // this.editor.config.filebrowserBrowseUrl = '/App/Back/Public/ckfinder/ckfinder.html'; // this.editor.config.filebrowserBrowseUrl = '/apps/ckfinder/3.4.5/ckfinder.html' // 上传图片路径 this.editor.config.filebrowserImageUploadUrl = environment.restBaseUrl + '/news'; // this.editor.config.filebrowserImageUploadUrl = '/news'; // this.editor.config.removeDialogTabs='image:advanced;link:advanced' // this.editor.config.removeDialogTabs='image:advanced;'; // this.editor.config.removeDialogTabs='image:advanced;image:linkId'; this.editor.config.removeDialogTabs = 'image:advanced;image:Link'; //预览区域显示内容 this.editor.config.image_previewText = ' '; this.editor.on('fileUploadResponse', (evt: any) => { // Prevent the default response handler. evt.stop();