Thanks to the power of Angular, encapsulating WangEditor components is very simple 1. Install wangeditor using yarn or npm
2. Create an Angular component
3. Encapsulate component logic 3.1 Template
3.2 ts logic import { Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild, ViewEncapsulation } from '@angular/core'; import { ControlValueAccessor } from '@angular/forms'; import E from "wangeditor" import hljs from 'highlight.js' import "node_modules/highlight.js/styles/xcode.css" @Component({ selector: 'q-wang-editor', templateUrl: './q-wang-editor.component.html', styleUrls: [ './q-wang-editor.component.less', '../../../../../node_modules/highlight.js/styles/xcode.css'], encapsulation: ViewEncapsulation.None, }) export class QWangEditorComponent implements OnInit, ControlValueAccessor,OnDestroy { @ViewChild("wang") editor!: ElementRef; @Input() value: string = ''; @Input() height = 300; @Output() valueChange = new EventEmitter(); onChange: ((value: string) => {}) | undefined; html = '' wangEditor: E | undefined; constructor() { } ngOnDestroy(): void { this.wangEditor?.destroy(); } writeValue(obj: any): void { this.html = obj; this.wangEditor?.txt.html(this.html) } registerOnChange(fn: any): void { } registerOnTouched(fn: any): void { } ngOnInit(): void { setTimeout(() => { this.wangEditor = new E(this.editor.nativeElement) this.wangEditor.config.zIndex = 500; this.wangEditor.config.height = this.height this.wangEditor.highlight = hljs; this.wangEditor.config.onchange = (html: any) => { this.valueChange.emit(html) if (this.onChange) { this.onChange(html); } } this.wangEditor.config.onchangeTimeout = 500; this.wangEditor.create(); this.wangEditor.txt.html(this.html) }, 200); } } The general idea:
4. Use components
5. Effect preview 6. Last The Angular component encapsulation of WangEditor is basically completed. If you need more functions, such as picture uploading, you can add functions according to your needs. This is the end of this article about Angular encapsulation of WangEditor rich text component. For more relevant Angular WangEditor rich text component content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed tutorial on installing Python 3.8.1 on Linux
>>: Eight common SQL usage examples in MySQL
Table of contents ESLint plugin installation in H...
This article example shares the specific code of ...
1. Introduction to Prometheus Prometheus is an op...
About let to avoid problems caused by closure Use...
Table of contents 1. Introduction to binlog 2. Bi...
01. Command Overview dirname - strip non-director...
Table of contents 【Function Background】 [Raw SQL]...
The inline-block property value becomes very usef...
This article shares with you a compound motion im...
Due to work requirements, I recently spent some t...
Neo4j (one of the Nosql) is a high-performance gr...
Preface nginx uses a multi-process model. When a ...
Preface I believe that the syntax of MySQL is not...
1: I won’t go into the details of how to install ...
Preface Before we start explaining the principle ...