npm i ngx-quill
app.module.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { ReactiveFormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; import { HelloComponent } from './hello.component'; import { QuillModule } from 'ngx-quill'; @NgModule({ imports: [ BrowserModule, ReactiveFormsModule, QuillModule.forRoot() ], declarations: [ AppComponent, HelloComponent ], bootstrap: [ AppComponent ], }) export class AppModule { } |
app.component.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import { Component } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; import Quill from 'quill'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { form: FormGroup; html: string; quillConfig={ toolbar: { container: [ ['bold', 'italic', 'underline', 'strike','image','video'], [{ 'size': ['xsmall', 'small', 'medium', 'large', 'xlarge']}], [{ 'align': [] }], ['clean'], ['link'], ], }, } constructor(){} ngOnInit() { this.form = new FormGroup({ 'text': new FormControl('<p><strong>Hello</strong> World!</p>') }); } onContentChanged = (event) =>{ //console.log(event.html); } public logValue(): void { const element = document.querySelector('.ql-editor'); this.html = element.innerHTML; } public logForm(): void { setTimeout(() => { console.log(this.form); console.log(`DIRTY: ${this.form.dirty}`); console.log(`TOUCHED: ${this.form.touched}`); }); } public blur(): void { console.log('blur'); } public onSelectionChanged(): void { console.log('onSelectionChanged'); } } |
app.component.html
1 2 3 4 5 6 7 8 9 |
<div [formGroup]="form"> <quill-editor placeholder="Enter Text" formControlName="text" [modules]="quillConfig" (onBlur)="blur()" (onSelectionChanged)="onSelectionChanged()"> </quill-editor> </div> |