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 What is the Linux system that w...
Problem Reproduction When using HTML for editing,...
When working on a recent project, I found that th...
<br />In the past, creating a printer-friend...
Table of contents background accomplish Supplemen...
When we do CSS web page layout, we all know that i...
Apache Tomcat is an open source software that imp...
I spent almost two hours trying various methods. ...
<br />Scientifically Design Your Website: 23...
How can you find the location of the configuratio...
One-click execution To install Python 3.8 in a vi...
This article uses an example to describe how MySQ...
The pitfalls of MySQL read-write separation The m...
ref definition: used to register reference inform...
For historical reasons, MySQL replication is base...