Ngx-quill toolbar customization not working - quill Cannot import modules

时间:2018-11-27 00:52:08

标签: angular quill angular7

UPDATE: I bailed ship when I realized PrimeNg had a quill implementation and I was already using PrimeNg. Wasn't working at first but upgrading to angular 7 and ngrx 7 beta fixed issues. https://www.primefaces.org/primeng/#/editor

I'm attempting the setup the ngx-quill text editor in my project with a more complete toolbar than the default one. I'm just copying this code snippet from the documentation and haven't tweaked (yet!).

I do not get any browser errors if I don't include the modules attribute but I'm wondering if I have an import issue that's only showing when I try to add it?

instructions.html

 <quill-editor modules="editorOptions"></quill-editor>

instructions.ts

import { Component, Input, Output, EventEmitter } from '@angular/core';
  import * as Quill from 'quill';

@Component({
    selector: 'instructions',
    templateUrl: '../admin/instructions.html'
})

export class Instructions {
    public editorOptions = {
        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
        ]
    };

Errors in the browser: Quill cannot load modules

3 个答案:

答案 0 :(得分:0)

嗨,您可能会收到此错误,因为modules是输入,应放在方括号中

 <quill-editor
    theme="bubble"
    [placeholder]="editorPlacehorder"
    [modules]="moduleConfig"
    [(ngModel)]="ngModelValue"
    (onContentChanged)="onContentChanged($event)">
  </quill-editor>

并确保已将模块QuillModule导入

import { QuillModule } from 'ngx-quill';

还将此模块添加到模块文件中,以便导入ex。 AppModule

imports: [
    QuillModule
]

并确保您已导入angular.json所有文件以使Quill正常工作

  "styles": [
          "node_modules/quill/dist/quill.core.css",
          "node_modules/quill/dist/quill.bubble.css",
          "node_modules/quill/dist/quill.snow.css",
          "node_modules/quill-emoji/dist/quill-emoji.css",
          "node_modules/quill-mention/dist/quill.mention.min.css"
        ],
        "scripts": [
          "node_modules/quill/dist/quill.min.js",
          "node_modules/quill-mention/dist/quill.mention.min.js"
        ]

如果您有任何问题,我希望这对您有用!

答案 1 :(得分:0)

在这里,我给出"ngx-quill": "^5.1.0"版本的答案。

在您的app.module.ts文件中

import { QuillModule } from 'ngx-quill';

@NgModule({
  imports: [QuillModule]
})

在您的style.css文件中

@import "~quill/dist/quill.bubble.css";
@import "~quill/dist/quill.snow.css";

在您的html文件中

<quill-editor [modules]="modules" [(ngModel)]="model"></quill-editor>
{{model}}

在您的打字稿文件中

model: string = '';

  modules: {
    toolbar: [
      ['bold', 'italic', 'underline', 'strike'],        // toggled buttons
      ['blockquote'],

      [{'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

    ]
  };

答案 2 :(得分:0)

即使您跳船了,也请相信这只是您的html:

<quill-editor modules="editorOptions"></quill-editor>

应该是

<quill-editor [modules]="editorOptions"></quill-editor>