I am trying to install ckeditor to my angular project. I already tried installing ckeditor4-angular
via npm but was unable to find a way to add plugins like the WIRIS mathType. Please how can i install the editor to my angular project and as well install plugins?
How to install CKEDITOR to angular project and add plugins
12.6k views Asked by emmaakachukwu AtThere are 3 answers
Following steps worked for me :
Copy the everything from "ckeditor5\build" folder to your assets folder.
Import the module in your app.module.ts file like -
//app.module.ts file import { CKEditorModule } from '@ckeditor/ckeditor5-angular'; ... imports:[..., CKEditorModule,] ...
- Now, in your component import the custom ckeditor like this -
import * as CustomEditor from '../../../assets/ckeditor.js';
- Create the object of editor like this
public Editor = CustomEditor.Editor;
Yes, you have to use Editor property from CustomEditor object
- Setup the ckeditor toolbar by settings its config property like :
<ckeditor [config]="{ toolbar: [ 'heading', '|', 'bold'. . . . ] }" [editor]="Editor">
Please make sure to set config property as it is going to complain if you don't.
After step 7
Add ckeditor code to package.json "dependencies": { ... "@ckeditor/ckeditor5-angular": "^1.1.2", ... }
Step 8:
npm install
step 9:
In app.module.ts file you can add
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 { }
step 10: In file tsconfig.json add allowJs: ture
"compilerOptions": {
"allowJs": true,
}
step 11:
Import CKEditor to your component:
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>'
};
}
step 12:
Add it too your template.html
<ckeditor [(ngModel)]="model.editorData" [editor]="Editor"></ckeditor>
Here is an issue regarding this https://github.com/ckeditor/ckeditor5-angular/issues/134. You need to create your custom CKEditor build and include necessary plugins into it. Here is the guide: https://ckeditor.com/docs/ckeditor5/latest/builds/guides/development/custom-builds.html BTW I suggest you to use CKEditor 5, the latest version.
UPD:
git clone https://github.com/ckeditor/ckeditor5-build-classic.git
npm install
npm install --save @wiris/mathtype-ckeditor5
src/ckeditor.js
and new plugin to the editor:yarn run build
build
folder to your project. For instancepackage.json
Hope this help you.