gpt4 book ai didi

javascript - 如何从 Controller 访问 ng-Quill 实例以更改 AngularJs 中的工具栏

转载 作者:行者123 更新时间:2023-11-30 07:54:10 25 4
gpt4 key购买 nike

我需要使用 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

最佳答案

最近我遇到了同样的问题然后我浏览了来自 hereng-quill 文档.

同时检查此处的问题 How to configure toolbar items?

有了这个组件,我们有两个自定义选项

  1. 使用 HTML 元素添加 <ng-quill-toolbar>
  2. 使用 ngQuillConfigProvider.set() 设置配置
  3. 使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com