ng2富文本编辑器 Quill

前端之家收集整理的这篇文章主要介绍了ng2富文本编辑器 Quill前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、安装

npm install ng2-quill-editor --save

2、主模块中引入

import { QuillEditorModule } from 'ng2-quill-editor';

@NgModule({
  // ...
  imports: [
    QuillEditorModule
  ],// ...
})
export class AppModule {}

3、组件中使用

A: 模板中(html)

// ngModel 双休数据绑定,获取富文本框中的数据
// config 配置对象
// 改变输入框的值,触发事件
<quill-editor [(ngModel)]="editorContent"
              [config]="editorConfig"
              (change)="onContentChanged($event)"></quill-editor>
              
B: 组件中

import { Component } from '@angular/core';

@Component({
  selector: "",templateUrl: ""
})
export class Sample{
  // 初始化值
  public editorContent = "";
  // 配置编辑器提醒文字
  public editorConfig = {
    placeholder: "输入公告内容支持html"
  };
  constructor() {}
  // 触发事件 html标记语言, text文本
  onContentChanged({ html,text }) {
    console.log(html,text);
  }
}

4、 界面中使用html标记语言注意事项

<div innerHTML="{{data}}"></div>

remark是含有标记语言的文本,所以使用下面的格式插入的html界面中

5、注意,富文本编辑器作为一个专门的组件,在需要用到的地方,直接标签引用,所以他的值需要@Output()到父组件,还有在编辑信息的时候,文本框显示原来的值,需要从父组件中获取值,@Input()。

原文链接:https://www.f2er.com/angularjs/148263.html

猜你在找的Angularjs相关文章