I installed CKEditor for Angular following this guide: https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/frameworks/angular.html
I imported CKEditorModule to my Module and added it to my imports.
import { CKEditorModule } from "@ckeditor/ckeditor5-angular";
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
CKEditorModule
],
providers: [],
bootstrap: [AppComponent]
})
In my component, I added the ClassicEditor build and assigned it to a public property.
import * as ClassicEditor from '@ckeditor/ckeditor5-build-classic';
export class AppComponent {
title = 'AngularCkeditor';
public Editor = ClassicEditor;
}
Finally I'm using the ckeditor tag in my html template:
<ckeditor [editor]="Editor" data="<p>Hello, world!</p>"></ckeditor>
It works pretty well!
Now I want to add some plugins to it but there is no explanation how to achieve that.
So I followed the default guide for installing plugins: https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/installing-plugins.html
For example I tried to install the Alignment plugin:
npm install --save @ckeditor/ckeditor5-alignment
Then I imported the plugin to my component and tried to load it.
import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment';
ClassicEditor.builtinPlugins = [
Alignment
];
When I do this I keep stucked with an error:
TypeError: Cannot read property 'getAttribute' of null
It's so strange because I followed the same guide to edit the configuration of CKEditor, and it works perfectly.
ClassicEditor.defaultConfig = {
toolbar: {
items: [
'heading',
'|',
'alignment',
'bold',
'italic',
'|',
'bulletedList',
'numberedList',
'|',
'link',
'blockQuote',
'|',
'imageUpload',
'|',
'undo',
'redo'
]
},
image: {
toolbar: [
'imageStyle:full',
'imageStyle:side',
'|',
'imageTextAlternative'
]
},
language: 'en'
};
For easier setup you can try the CKEditor 5 online builder, just pick plugins you want to use, download ready to use build and attach it inside your Angular application. Sorry, something went wrong. Half a year later it's still extremely difficult to extend the classic build with plugins in an Angular environment.
Install created project (the plugin) into CKEditor 5 build project (the one downloaded). If your plugin requires some modules from packages which are not available in this npm project, just feel free to run npm install --save-dev @ckeditor/ckeditor5-whateveryouneed. I am following the beginning of this tutorial.
No, you should download the ckeditor5-build-classic package outside of the node_modules directory (like a new project). Otherwise, you will lose all your changes done inside node_modules after calling npm install. Then after installing and generating the custom build, you should copy the file to the angular project and import it from the component.
Yes you are fully configurable and I've always loved CKEditor in the past, but this system you are suggesting is literally ridiculous. CKEditor needs to simplify how its customers are using its library. Adding a new button should be as simple as: use NEW_BUTTON or config= {toolbar: } where the config merges with the previous one.
Actually, the 'builtinPlugins' configuration must be done directly in the build instead our component, as explained in the guide: https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/installing-plugins.html#adding-a-plugin-to-a-build
Adding plugins to existing builds is done through their customization. Editor builds are maintained in their respective GitHub repositories. Therefore, assuming that you want to customize the classic editor build you need to:
- Clone the build repository.
- Install the plugin package.
- Add it to the build configuration.
- Bundle the build.
We must create a 'custom build', and then import it in our component.
Take a look at the example of adding MathType plugin, you can do the same way for your case https://stackoverflow.com/a/59225002/6465520
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With