Integrating CKEditor 5 with Angular multi-root editor component from CDN
This page focuses on describing the usage of the multi-root editor in Angular applications. For other editor types, see the default Angular integration.
The Angular multi-root editor integration is in early access. Its API is not stable and may change in any release without a major version bump.
The multi-root editors in Angular are supported since version 13.1.0 of this package.
This guide assumes you already have an Angular project. To create such a project, you can use Angular CLI. Refer to the Angular documentation to learn more.
To use our Cloud CDN services, create a free account. Learn more about license key activation.
First, install the CKEditor 5 WYSIWYG editor component for Angular:
npm install @ckeditor/ckeditor5-angularCopy codeAngular is a TypeScript-first environment, so you may need to import TypeScript types for CKEditor. Depending on the plugins and features you use, you may also need to install the required open-source and premium packages:
npm install --save-dev ckeditor5 # Open-source plugin types.
npm install --save-dev ckeditor5-premium-features # Premium features plugin types.Copy codeUse the loadCKEditorCloud helper to load the editor code and plugins from CDN, and pass the MultiRootEditor class it returns to the <ckeditor-multi-root> component. For more information about the loadCKEditorCloud helper, see the Loading CDN resources guide.
// app.component.ts
import { Component, type OnInit } from '@angular/core';
import {
CKEditorMultiRootComponent,
loadCKEditorCloud,
type CKEditorCloudResult,
type MultiRootEditorData
} from '@ckeditor/ckeditor5-angular';
import type { EditorConfig, MultiRootEditor } from 'https://cdn.ckeditor.com/typings/ckeditor5.d.ts';
@Component( {
selector: 'app-root',
imports: [ CKEditorMultiRootComponent ],
template: `
@if ( Editor && config ) {
<ckeditor-multi-root
[editor]="Editor"
[config]="config"
[(data)]="data"
/>
}
`
} )
export class AppComponent implements OnInit {
public Editor: typeof MultiRootEditor | null = null;
public config: EditorConfig | null = null;
public data: MultiRootEditorData = {
intro: '<h1>Angular multi-root editor</h1>',
content: '<p>Hello from CKEditor 5 multi-root!</p>'
};
public ngOnInit(): void {
loadCKEditorCloud( {
version: '49.1.0',
premium: true
} ).then( this._setupEditor.bind( this ) );
}
private _setupEditor( cloud: CKEditorCloudResult<{ version: '49.1.0', premium: true }> ) {
const { MultiRootEditor, Essentials, Paragraph, Bold, Italic } = cloud.CKEditor;
const { FormatPainter } = cloud.CKEditorPremiumFeatures;
this.Editor = MultiRootEditor;
this.config = {
licenseKey: '<YOUR_LICENSE_KEY>',
plugins: [ Essentials, Paragraph, Bold, Italic, FormatPainter ],
toolbar: [ 'undo', 'redo', '|', 'bold', 'italic', '|', 'formatPainter' ]
};
}
}Copy codeWithout any content inside, the <ckeditor-multi-root> component renders the toolbar followed by the editables of all roots. When config.menuBar.isVisible is set to true, it renders the menu bar above the toolbar, too.
To build a custom layout, put the <ckeditor-multi-root-toolbar>, <ckeditor-multi-root-menu-bar>, and <ckeditor-multi-root-editable> components inside the <ckeditor-multi-root> component. The npm guide shows how.
The component works the same regardless of the distribution. See the npm guide for:
- The supported
@Inputproperties. - The supported
@Outputproperties. - The
addRoot()andremoveRoot()methods, and theroots()signal. - Two-way data binding.
The source code of rich text editor component for Angular is available on GitHub in https://github.com/ckeditor/ckeditor5-angular.
- See how to manipulate the editor’s data in the Getting and setting data guide.
- Refer to further guides in the setup section to see how to customize your editor further.
- Check the features category to learn more about individual features.