5

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?

emmaakachukwu
  • 515
  • 1
  • 7
  • 16

3 Answers3

19

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:

  1. Clone the original repo:

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

  1. Install dependencies

npm install

  1. Install necessary plugin itself

npm install --save @wiris/mathtype-ckeditor5

  1. Open src/ckeditor.js and new plugin to the editor:
...
import MathType from '@wiris/mathtype-ckeditor5';
...

ClassicEditor.builtinPlugins = [
   ...
   MathType
];

ClassicEditor.defaultConfig = {
    toolbar: {
        items: [
            ...
            'MathType',
            ...
        ]
    },
    ...
};
  1. Then build the editor (you maybe need to install yarn)

yarn run build

  1. After that copy everything from build folder to your project. For instance
src/assets/js/ck-editor-math-type/
   -> translations
      -> ...
   -> ckeditor.js
  1. Add ckeditor code to package.json
"dependencies": {
   ...
   "@ckeditor/ckeditor5-angular": "^1.1.2",
   ...
}
  1. 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>'
    };
}
  1. Add it too your template.html
<ckeditor [(ngModel)]="model.editorData" [editor]="Editor"></ckeditor>

Hope this help you.

Maksim Vorontsov
  • 799
  • 8
  • 18
  • Okay. I will love to see the steps as you progress. – emmaakachukwu Dec 07 '19 at 21:43
  • 5
    I am getting duplicate module error, exactly followed the procedure. – Yoku Mar 05 '20 at 12:14
  • 2
    In case anybody wants to use it as an `npm` package, push it up to your github repository ( gitusername/gitbranch ) (on github.com) and use it in package.json as `... "gitbranch": "gitusername/gitbranch#commit-id", ... `. Commit is to ensure you always have the same version. Hope this helps. – Nico Apr 16 '20 at 10:34
  • after 7th step do i need to import Ckeditor module in my feature module – paruvelly Vishwanath May 28 '20 at 08:01
  • Here is the elaborated step #7 https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/frameworks/angular.html – Ratul Sharker Jun 01 '20 at 18:45
  • I had to set "strict": false in tsconfig.json. If someone has a better solution to solve error 'Could not find a declaration file for module' let me know! – Wim den Herder May 16 '21 at 07:45
3

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>
1

Following steps worked for me :

  1. Copy the everything from "ckeditor5\build" folder to your assets folder.

  2. Import the module in your app.module.ts file like -

//app.module.ts file
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
...
imports:[..., CKEditorModule,]
...
  1. Now, in your component import the custom ckeditor like this -

import * as CustomEditor from '../../../assets/ckeditor.js';

  1. Create the object of editor like this

public Editor = CustomEditor.Editor;

Yes, you have to use Editor property from CustomEditor object

  1. 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.