angular - 将 Quill 文本编辑器集成到 Angular 应用程序中

标签 angular quill ngx-quill

我正在学习如何创建博客网站。我首先尝试了一个简单的例子。但文本编辑器没有显示在我的屏幕上。我使用 npm install --save quill@1.3.6 ngx-quill 命令安装了 Quill。我的 app.component.html 非常简单。

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand ml-auto mr-auto" href="#">Quill JS Editor with Angular</a>
</nav>

<div class="container">
  <div class="row pt-5">
    <div class="col-md-8">
      <form [formGroup]="editorForm" (ngSubmit)="onSubmit()">
        <div class="form-group">
          <label for="editor">
            <h3>Editor</h3>
          </label>
          <quill-editor></quill-editor>
        </div>
      </form>
    </div>
    <div class="col-md-4 bg-light p-4">
      <h3>Output</h3>
      <p class="my-5"></p>
    </div>
  </div>
</div>

其实应该是这样的。 enter image description here

我还在我的 app.component.ts 中从 @angular/forms 导入了 FormGroupFormControl其中包含以下代码。

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  editorForm: FormGroup;
  ngOnInit() {
    this.editorForm = new FormGroup({
      'editor': new FormControl(null)
    })
  }
}

但我收到此错误。 enter image description here

整个项目位于 github 。请告诉我这个项目中还缺少什么。

最佳答案

按照以下步骤操作应该可以:

1-安装:

 npm install ngx-quill
 npm install @angular/core
 npm install @angular/common
 npm install @angular/forms
 npm install @angular/platform-browser
 npm install quill
 npm install rxjs — peer dependencies of rxjs-quill
  • 在您的index.html中包含主题样式:quilljs的bubble.css、snow.css,或者使用@import语句将它们添加到您的css/scss文件中,或者将它们添加到您的index.html中构建过程。

使用以下代码更新 angular.json 文件:

  “styles”: [
          “./node_modules/@angular/material/prebuilt-themes/indigo-pink.css”,
          “src/styles.css”,
          “./node_modules/quill/dist/quill.core.css”,
          “./node_modules/quill/dist/quill.snow.css”
        ],
        “scripts”: [“./node_modules/quill/dist/quill.js”]

将其导入您的 app.module.ts

   import { QuillModule } from 'ngx-quill'

并在导入中添加如下所示

 @NgModule({
  declarations:[],
  imports:[
    CommonModule,
    QuillModule.forRoot(),
  ]
 })

在您的 component.ts 文件中,您可以修改编辑器样式,如以下代码:

   editorStyle = {
     height: '200px'
   };

在你的 component.html 文件中你可以像下面的代码那样调用它:

 <div id="quill">
                <p>Content *</p>
                <quill-editor [styles]="editorStyle" placeholder="Enter Text" [modules]="config"
                    formControlName="yourCtrlname" required>
                </quill-editor>
            </div>

您还可以检查:https://lifecoders.wordpress.com/angular/quill-rich-text-editor-setup-in-angular-7-8/

这里:https://www.npmjs.com/package/ng-quill

关于angular - 将 Quill 文本编辑器集成到 Angular 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57631897/

相关文章:

html - ngx-quill 中的空白

angular - Angular 5 中 Angular @angular/http URLSearchParams 类的替代品是什么

html - 从数组 typescript 中删除对象(Angular 2)

javascript - 如何将 html 标签添加到 Angular 中 Quill 文本编辑器的内容 div?

html - 在 Chrome 中将插入符定位在具有大行高的 contenteditable 中

javascript - 在 Quill Rich Editor 中包含标题

angular - 如何在 Angular 应用程序中添加自定义 Quill 工具栏

javascript - 为什么在 groupBy 运算符之后不调用 subscribe?

angular - 未满足的对等依赖@ionic-native/native-audio

javascript - 如何更改 QuillJS (react-js) 中的默认标题名称?