angular4 富文本编辑器
使用quill富文本编辑器实现,angular项目中用到了ngx-quill插件。
quill的GitHub地址:https://github.com/quilljs/quill
ngx-quill的GitHub地址:https://github.com/KillerCodeMonkey/ngx-quill
ngx-quill适用于版本号在2以及以上的angular。
具体操作如下:
1、ngx-quill的安装
angular >= 5时ngx-quill的安装
npm install ngx-quill
angular < 5时
npm install ngx-quill@1.6.0
2、quill的配置
引入(ngx-quill的)QuillModule :
import { QuillModule } from 'ngx-quill'
在你的NgModule中添加 QuillModule :
@NgModule({
imports: [
...,
QuillModule
],
...
})
在index.html中添加quill的样式 :
<link href="https://cdn.quilljs.com/1.0.0/quill.snow.css" rel="stylesheet">
3、使用
在页面使用标签<quill-editor></quill-editor>进行使用,效果如下:

上图中的工具类是配置后的工具类,代码如下:
<quill-editor [modules]="config" [style]="{height: '200px'}" [(ngModel)]="data.content"></quill-editor>
config的内容如下:
{
toolbar: [
//['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
//[{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
//[{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
//[{ 'direction': 'rtl' }], // text direction
//[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
//[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
//[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
//[{ 'font': [] }],
//[{ 'align': [] }],
//['clean'], // remove formatting button
['link', 'image', 'video'] // link and image, video
]
};
-------------------------------------------------
2018-05-13 16:13:20
自定义工具栏
<quill-editor [style]="{height: '200px'}" [(ngModel)]="data.content" placeholder="在这里详细描述一个推荐原因,\n">
<div quill-editor-toolbar>
<span class="ql-formats">
<button type="button" class="ql-header" value=""></button>
<button type="button" class="ql-header" value=""></button>
<button type="button" class="ql-blockquote"></button>
<button type="button" class="ql-code-block ql-active"></button>
<button type="button" class="ql-list" value="ordered"></button>
</span>
<span class="ql-formats">
<button type="button" class="ql-link"></button>
<button type="button" style="outline:none">
<div class="upload_img">
<svg class="camera" viewBox="0 0 18 18"> <rect class="ql-stroke" height="" width="" x="" y=""></rect> <circle class="ql-fill" cx="" cy="" r=""></circle> <polyline class="ql-even ql-fill" points="5 12 5 11 7 9 8 10 11 7 13 9 13 12 5 12"></polyline> </svg>
<input type="file" class="file_input" ng2FileSelect [uploader]="uploader2" />
</div>
</button>
</span>
<span class="ql-formats">
<p style="font-size: 9px;" *ngIf="uploader2?.queue.length > 0">图片已上传:{{ uploader2?.queue.length > ? uploader2?.queue[uploader2?.queue.length-]?.progress : }}%</p>
</span>
</div>
</quill-editor>
上传图片代码(使用了ng2-file-upload插件)
public uploader2: FileUploader;
this.uploader2 = new FileUploader({
url: this.URL
, method: "POST"
, itemAlias: "upfile"
, autoUpload: true
});
this.uploader2.onSuccessItem = function (item, response, status, headers) {
if(status == ){
let rsp = JSON.parse(response);
let img = '<img class="camera" src="'+"http://您的域名"+ rsp.url+'" alt="">';
that.data.content += img;
}
};

angular4 富文本编辑器的更多相关文章
- 富文本编辑器Simditor的简易使用
最近打算自己做一个博客系统,并不打算使用帝国cms或者wordpress之类的做后台管理!自己处于学习阶段也就想把从前台到后台一起谢了.好了,废话不多说了,先来看看富文本编辑器SimDitor,这里是 ...
- 个人网站对xss跨站脚本攻击(重点是富文本编辑器情况)和sql注入攻击的防范
昨天本博客受到了xss跨站脚本注入攻击,3分钟攻陷--其实攻击者进攻的手法很简单,没啥技术含量.只能感叹自己之前竟然完全没防范. 这是数据库里留下的一些记录.最后那人弄了一个无限循环弹出框的脚本,估计 ...
- UEditor百度富文本编辑器--让编辑器自适应宽度的解决方案
UEditor百度富文本编辑器的initialFrameWidth属性,默认值是1000. 不能够自适应屏幕宽度.如图1: 刚开始的时候,我是直接设置initialFrameWidth=null的.效 ...
- PHP Ueditor 富文本编辑器
2016年12月11日 08:46:59 星期日 百度的简版富文本编辑器umeditor很久没更新了 全功能版本的配置项跟umeditor还是有区别的, 这里说下ueditor怎么对接到项目中去, 主 ...
- JavaScript 富文本编辑器
WEB项目中使用UEditor(富文本编辑器) UEditor - 完整示例 http://ueditor.baidu.com/website/onlinedemo.html UEditor注意事项: ...
- MVC 使用 Ueditor富文本编辑器
一.Ueditor 1.下载Ueditor富文本编辑器 官方下载地址: http://ueditor.baidu.com/website/download.html 建议下载开发版,此处我下载的是 . ...
- 富文本编辑器kindeditor配置
<!--富文本编辑器kindeditor配置↓ --> <link type="text/css" rel="stylesheet" href ...
- web开发实战--弹出式富文本编辑器的实现思路和踩过的坑
前言: 和弟弟合作, 一起整了个智慧屋的小web站点, 里面包含了很多经典的智力和推理题. 其实该站点从技术层面来分析的话, 也算一个信息发布站点. 因此在该网站的后台运营中, 富文本的编辑器显得尤为 ...
- 富文本编辑器防止xss注入javascript版
富文本编辑器:ueditor 其实富文本编辑器已经有防止xss注入功能,但是你服务端程序在接收的时候在做一次转义,否则有可能然后前端验证直接提交数据导致被xss攻击. 为了节省后端程序开销则在前端 显 ...
随机推荐
- spring mvc 简单的文件上传与下载
上传文件有很多种方法,这里主要讲解的是spring mvc内提供的文件上传 前提使用:spring mvc 在这个之前我们需要把环境给配置好 1:springmvc的XML配置文件加上这一段就即可, ...
- 从身份证管理系统思考企业CMDB的建设
关注嘉为科技,获取运维新知 对大部分中大型的企业来说,CMDB建设对于整个IT服务和IT运维管理的重要性不言而喻,但是目前仍然有非常多的企业无法建设好CMDB. 我最近刚好接触了一个公安系统的朋友,他 ...
- java 获取微信公众号code为空
失败的原因是没将回调方法encode转换 /** * URL编码(utf-8) * * @param source * @return */ public static String urlEncod ...
- vue版 弹幕
效果: 下载 优化版下载: https://pan.baidu.com/s/1mvKGwJsBjXd2hvvi5Rp9pA 用法: import barrage from '../components ...
- JMETER-01
jmter安装 1.Linxu安装: 步骤:下载JMeter包-->解压包-->赋权限-->配置环境变量-->测试服务 1.下载:wget http://mirrors.hus ...
- 前后端token机制 识别用户登录信息
Token,就是令牌,最大的特点就是随机性,不可预测.一般黑客或软件无法猜测出来. 那么,Token有什么作用?又是什么原理呢? Token一般用在两个地方: 1)防止表单重复提交. 2)anti c ...
- pycharm配置QtDesigner
QtDesigner C:\Qt\Qt5.12.2\5.12.2\mingw73_64\bin\designer.exe $ProjectFileDir$ Pyuic C:\Anaconda3\pyt ...
- 超详细的PDF Expert的注释功能介绍
今天,要给大家很是详细地介绍一下PDF Expert(一款专门在mac上使用的PDF阅读编辑器)的注释功能,让有点健忘的各位小伙伴们通过积极地与文本交互,从而记住更多的专业书内容. 具体使用方法请看以 ...
- jquery源码解读
最近一直在研读 jQuery 源码,初看源码一头雾水毫无头绪,真正静下心来细看写的真是精妙,其结构明晰,高内聚.低耦合,兼具优秀的性能与便利的扩展性,在浏览器的兼容性(功能缺陷.渐进增强)优雅的处理能 ...
- Servlet CDI Example Analysis
上下文和依赖注入(CDI)使您的对象能够自动为它们提供依赖项,而不是创建它们或将它们作为参数接收.CDI还为您管理这些依赖项的生命周期. 例如,来看下面这个servlet: @WebServlet(& ...