【问题标题】:How to install CKEDITOR to angular project and add plugins如何将 CKEDITOR 安装到 Angular 项目并添加插件
【发布时间】:2020-03-31 15:30:34
【问题描述】:

我正在尝试将 ckeditor 安装到我的 Angular 项目中。我已经尝试通过 npm 安装ckeditor4-angular,但无法找到添加像 WIRIS mathType 这样的插件的方法。请问如何将编辑器安装到我的角度项目并安装插件?

【问题讨论】:

标签: angular ckeditor editor wiris


【解决方案1】:

这里有一个关于这个https://github.com/ckeditor/ckeditor5-angular/issues/134 的问题。您需要创建自定义 CKEditor 构建并在其中包含必要的插件。这是指南:https://ckeditor.com/docs/ckeditor5/latest/builds/guides/development/custom-builds.html 顺便说一句,我建议你使用最新版本的 CKEditor 5。

更新:

  1. 克隆原始存储库:

git clone https://github.com/ckeditor/ckeditor5-build-classic.git

  1. 安装依赖项

npm install

  1. 自行安装必要的插件

npm install --save @wiris/mathtype-ckeditor5

  1. 打开src/ckeditor.js 和编辑器的新插件:
...
import MathType from '@wiris/mathtype-ckeditor5';
...

ClassicEditor.builtinPlugins = [
   ...
   MathType
];

ClassicEditor.defaultConfig = {
    toolbar: {
        items: [
            ...
            'MathType',
            ...
        ]
    },
    ...
};
  1. 然后构建编辑器(你可能需要安装 yarn)

yarn run build

  1. 之后,将 build 文件夹中的所有内容复制到您的项目中。例如
src/assets/js/ck-editor-math-type/
   -> translations
      -> ...
   -> ckeditor.js
  1. 将ckeditor代码添加到package.json
"dependencies": {
   ...
   "@ckeditor/ckeditor5-angular": "^1.1.2",
   ...
}
  1. 将 CKEditor 导入您的组件:
import * as ClassicEditor from '../../assets/js/ck-editor-math-type/ckeditor.js';

...
export class CkeditComponent implements OnInit {

    public Editor = ClassicEditor;

    public model = {
        editorData: '<p>Hello, world!</p>'
    };
}
  1. 将它也添加到你的 template.html
<ckeditor [(ngModel)]="model.editorData" [editor]="Editor"></ckeditor>

希望对您有所帮助。

【讨论】:

  • 好的。随着您的进步,我很乐意看到这些步骤。
  • 我收到重复模块错误,完全按照程序进行。
  • 如果有人想将它用作 npm 包,请将其推送到您的 github 存储库( gitusername/gitbranch )(在 github.com 上)并在 package.json 中以 @987654337 的形式使用它@。提交是为了确保您始终拥有相同的版本。希望这会有所帮助。
  • 第 7 步后我需要在我的功能模块中导入 Ckeditor 模块
【解决方案2】:

第 7 步之后

将 ckeditor 代码添加到 package.json “依赖”:{ ... "@ckeditor/ckeditor5-angular": "^1.1.2", ... }

第 8 步:

npm 安装

第 9 步:

在 app.module.ts 文件中可以添加

import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
import { FormsModule } from '@angular/forms'; 
import { ReactiveFormsModule } from '@angular/forms'; 

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    ReactiveFormsModule,
    CKEditorModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

第 10 步: 在文件 tsconfig.json 中添加 allowJs: ture

"compilerOptions": {
    "allowJs": true,
}

第 11 步:

将 CKEditor 导入到您的组件中:

import * as ClassicEditor from '../../assets/js/ck-editor-math-type/ckeditor.js';

...
export class CkeditComponent implements OnInit {

    public Editor = ClassicEditor;

    public model = {
        editorData: '<p>Hello, world!</p>'
    };
}

第 12 步:

将它也添加到你的 template.html

<ckeditor [(ngModel)]="model.editorData" [editor]="Editor"></ckeditor>

【讨论】:

  • 花了一整天的时间在互联网上尝试各种资源,但无法让它发挥作用。
  • 如果你愿意,我已经完成了,你可以通过这个网址github.com/sarveshhome/ckeditorwithMathPhysics
  • 对于仍有问题的任何人,请确保您在 tsconfig.json 中的目标是 es2015 或更高的 "target": "es2015"
【解决方案3】:

以下步骤对我有用:

  1. 将“ckeditor5\build”文件夹中的所有内容复制到您的资产文件夹。

  2. 在您的 app.module.ts 文件中导入模块,例如 -

//app.module.ts 文件
从'@ckeditor/ckeditor5-angular'导入{CKEditorModule};
...
进口:[...,CKEditorModule,]
...
  1. 现在,在您的组件中像这样导入自定义 ckeditor -

从 '../../../assets/ckeditor.js' 导入 * 作为 CustomEditor;

  1. 像这样创建编辑器的对象

公共编辑器 = CustomEditor.编辑器;

是的,您必须使用来自 CustomEditor 对象的 Editor 属性

  1. 通过设置 ckeditor 工具栏的 config 属性来设置它:

[config]="{ toolbar: [ 'heading', '|', 'bold'... ] }" [editor]="Editor">

请确保设置配置属性,否则会报错。

【讨论】:

    猜你喜欢
    • 2020-04-30
    • 2019-07-31
    • 2016-04-05
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-17
    相关资源
    最近更新 更多