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

2024-01-19

我正在学习如何创建博客网站。我首先尝试了一个简单的例子。但文本编辑器没有显示在我的屏幕上。我安装了 Quillnpm install --save [email protected] /cdn-cgi/l/email-protection ngx-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>

Actually it should look like. enter image description here

我也导入了FormGroup and FormControl from @angular/forms in my app.component.ts其中包含以下代码。

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)
    })
  }
}

But I am getting this error. enter image description here

整个项目正在进行中github https://github.com/tmtanzeel/angular-blog-three。请告诉我这个项目中还缺少什么。


请按照以下步骤操作,它应该可以工作:

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中包含主题样式:bubble.css、quilljs的snow.css,或者将它们添加到你的css/scss文件中@import语句,或者在构建过程中添加它们的外部样式。

使用以下代码更新 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://lifecoders.wordpress.com/angular/quill-rich-text-editor-setup-in-angular-7-8/

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 Quill 文本编辑器集成到 Angular 应用程序中 的相关文章