Sign up (with export icon)

Integrating CKEditor 5 with Angular multi-root editor component from CDN

Contribute to this guideShow the table of contents

This page focuses on describing the usage of the multi-root editor in Angular applications. For other editor types, see the default Angular integration.

Experimental

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.

Note

The multi-root editors in Angular are supported since version 13.1.0 of this package.

Quick start

Copy link

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.

Note

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-angular
Copy code

Angular 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 code

Use 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 code

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

Component API

Copy link

The component works the same regardless of the distribution. See the npm guide for:

Contributing and reporting issues

Copy link

The source code of rich text editor component for Angular is available on GitHub in https://github.com/ckeditor/ckeditor5-angular.

Next steps

Copy link