在Angular11中使用wangEditor,并使用base64保存图片

1、alain中自带的几款。

2、创建项目、创建组件后装载wangeditor。

npm i wangeditor

3、在ts中引入wangeditor。

import * as WangEditor from 'wangeditor';

4、在html设置div容器,放置富文本编辑器。

<div id="editor" style="width: 750px; min-height: 100px"></div>

5、在ts中初始化编辑器。

editor: any;
  ngOnInit() {
    // @ts-ignore
    this.editor = new WangEditor('#editor');
    this.editor.config.uploadImgShowBase64 = true;  //使用base64保存图片,即可以上传本地图片
    this.editor.create();
  }

6、读取出文本框中html。

 this.conhtml = this.editor.txt.html();

7、将保存的文本重新编辑。

 this.editor.txt.html(res.comcontent);

8、页面上展示出文本框编辑并保存的内容。

//html代码
<div [innerHTML]="content | html" ></div>
//ts代码
if (this.record.comid != null) {
      this.comService.getCompetitionFindbyid(this.record.comid).subscribe((res) => {
        this.content = res.comcontent;
      });
    }

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值