作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要使用 angular 更改 quill.Js 的工具栏,我尝试使用 <ng-quill-toolbar></ng-quill-toolbar>
但是它没有按预期工作并且在多个编辑器上它导致错误,有没有一种方法可以使用 quill.Js 文档中给出的选项使用 Angular 更改它
https://quilljs.com/docs/configuration/
模块配置
(function() {
'use strict';
angular
.module('app')
.config(['ngQuillConfigProvider', function (ngQuillConfigProvider) {
ngQuillConfigProvider.set();
}]);
})();
Controller
(function () {
'use strict';
angular
.module('app')
.controller('Ctrl', Ctrl);
function Ctrl($document) {
var doc = $document[0];
var container = doc.getElementsByClassName('editor');
var toolbarOptions = [
['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
];
var options = {
debug: 'info',
modules: {
toolbar: toolbarOptions
},
placeholder: 'Compose an epic...',
readOnly: true,
theme: 'snow'
};
var editor = new Quill(container, options); //this instance is not initializing
}
})();
HTML
<ng-quill-editor name="description"
required theme="snow"
placeholder="Enter your question here"
ng-model="vm.QUES"
class="editor">
</ng-quill-editor>
Error: var editor = new Quill(container, options); //this instance is not initializing
最佳答案
最近我遇到了同样的问题然后我浏览了来自 here 的 ng-quill 文档.
同时检查此处的问题 How to configure toolbar items?
有了这个组件,我们有两个自定义选项
<ng-quill-toolbar>
ngQuillConfigProvider.set()
设置配置modules
ng-quill-editor
的属性组件1.使用HTML元素添加<ng-quill-toolbar>
请查看示例here .
2.使用ngQuillConfigProvider
我使用了以下代码来定制编辑器
.config(['ngQuillConfigProvider', function (ngQuillConfigProvider) {
var config = {
modules: {
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'] // link and image, video
]
},
theme: 'snow',
placeholder: 'Insert text here ...'
}
ngQuillConfigProvider.set(config);
}]);
3.使用ng-quill-editor组件的modules属性
在 Controller 中添加你的编辑器模块
$scope.editorModules = {
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'] // link and image, video
]
}
并将其添加到 View 中,如下所示
<ng-quill-editor modules="editorModules"
placeholder="Some text here"
ng-model="message">
</ng-quill-editor>
希望这会对某人有所帮助!
关于javascript - 如何从 Controller 访问 ng-Quill 实例以更改 AngularJs 中的工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44715969/
我是一名优秀的程序员,十分优秀!