Skip to content

Full featured editor

Use the following config to created a full featured editor

app.module.ts
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgxEditorModule, schema } from 'ngx-editor';
import { schema } from 'ngx-editor/schema';
@NgModule({
imports: [
FormsModule,
NgxEditorModule.forRoot({
locals: {
// menu
bold: 'Bold',
italic: 'Italic',
code: 'Code',
blockquote: 'Blockquote',
underline: 'Underline',
strike: 'Strike',
bullet_list: 'Bullet List',
ordered_list: 'Ordered List',
heading: 'Heading',
h1: 'Header 1',
h2: 'Header 2',
h3: 'Header 3',
h4: 'Header 4',
h5: 'Header 5',
h6: 'Header 6',
align_left: 'Left Align',
align_center: 'Center Align',
align_right: 'Right Align',
align_justify: 'Justify',
text_color: 'Text Color',
background_color: 'Background Color',
// popups, forms, others...
url: 'URL',
text: 'Text',
openInNewTab: 'Open in new tab',
insert: 'Insert',
altText: 'Alt Text',
title: 'Title',
remove: 'Remove',
enterValidUrl: 'Please enter a valid URL',
},
}),
],
})
export class AppModule {}
app.component.ts
import { Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
import { AbstractControl, FormControl, FormGroup } from '@angular/forms';
import { Validators, Editor, Toolbar } from 'ngx-editor';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class AppComponent implements OnInit, OnDestroy {
editor: Editor;
toolbar: Toolbar = [
['bold', 'italic'],
['underline', 'strike'],
['code', 'blockquote'],
['ordered_list', 'bullet_list'],
[{ heading: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] }],
['link', 'image'],
['text_color', 'background_color'],
['align_left', 'align_center', 'align_right', 'align_justify'],
];
form = new FormGroup({
editorContent: new FormControl('', Validators.required()),
});
ngOnInit(): void {
this.editor = new Editor();
}
ngOnDestroy(): void {
this.editor.destroy();
}
}
app.component.html
<form [formGroup]="form">
<div class="NgxEditor__Wrapper">
<ngx-editor-menu [editor]="editor" [toolbar]="toolbar"> </ngx-editor-menu>
<ngx-editor [editor]="editor" formControlName="editorContent"> </ngx-editor>
</div>
</form>