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
I followed the tutorial on W3school. I think the t...
There are three types of virtual hosts supported ...
Implementation effect: 1. count(1) and count(*) W...
The garbled code problem is as follows: The reaso...
Table of contents 1. Introduction to pid-file 2.S...
Table of contents 1. typeof 2. instanceof 3. Diff...
Excel export always fails in the docker environme...
Table of contents SQL execution order bin log Wha...
This article example shares the specific implemen...
Table of contents What is MySQL NDB Cluster Preli...
The first one is to use jQuery's ajax to send...
background During the project development process...
Table of contents Preface 1. Project Architecture...
introduce A chart is a graphical representation o...
1) Enter the folder path where the jdk file is st...