【问题标题】:PrimeNg Editor is not showing up - AngularPrimeNg 编辑器未显示 - Angular
【发布时间】:2019-02-17 12:19:40
【问题描述】:

我已经学习了很多教程,但到目前为止,我还没有设法让 PrimeNG 的编辑器模块出现! (Toast 或按钮等其他模块工作正常,只有编辑器不工作)。

这就是我所做的:

在 app.module.ts 中导入模块

import { EditorModule } from 'primeng/editor';

已安装的包

npm install quill --save

npm install @types/quill --save

更新了 angular-cli.json

"styles": [ "../node_modules/quill/dist/quill.core.css", "../node_modules/quill/dist/quill.snow.css", ] 
"scripts": [ "../node_modules/quill/dist/quill.js" ]

以 2 种不同方式插入 HTML

<p-editor [(ngModel)]="text" [style]="{'height':'320px'} ngDefaultControl"></p-editor>

<form style="text-align: center; margin: 0 auto; width: auto" [formGroup]="avisoForm" (ngSubmit)="atualizarCargo()">
...
<p-editor formControlName="msgAviso" [style]="{'height':'320px'}" ngDefaultControl></p-editor>

</form>

在 TS 文件中引用它们

this.avisoForm = new FormGroup({
        msgAviso: new FormControl,
        titAviso: new FormControl
    })

text: string;

但它并没有向最终用户显示任何内容,即使 p-editor 标记显示在那里:

End-User Screen

我认为这可能是 CSS 问题,但我检查了 CSS 文件,但我几乎无法检索到标签,因为它在页面中没有显示任何内容。 (我已经从 PrimeNG 原始网站搜索了一个,它有一个标签,但它也不在 CSS 中)。

我已经搜索了很多资源,但我还没有找到任何解决该问题的答案,有人可以帮助我吗?谢谢!

来源:

【问题讨论】:

  • 控制台有错误吗?
  • @SayusiAndo 控制台上没有错误。有一些与 formGroup 相关的错误,但我设法用 'ngDefaultControl' 解决了它
  • 做逆向工程不要用任何form,formcontrol,只创建Editor,看看有没有用?
  • 我试图复制这个但没有成功。卸载primeng quell 并执行npm cache clean。尝试再次安装它,不要安装 install @types。

标签: javascript html css angular primeng


【解决方案1】:

需要将 quill 的资源添加到您的应用程序中。使用 CLI 的示例设置如下;

npm install quill --save

将 Quill 添加到 angular.json

中的脚本
"scripts": [... "node_modules/quill/dist/quill.js"],

将 Quill css 添加到 angular.json

中的样式
"styles": [ ... "node_modules/quill/dist/quill.core.css", 
"node_modules/quill/dist/quill.snow.css"],

我已经用新的 angular 7 和现有项目多次检查了这个解决方案,它就像魅力一样 :)

【讨论】:

    【解决方案2】:

    刚才我为 PrimeNg Editor 创建了一个项目

    1. 使用最新版本 6 创建了新的 Angular 项目
    2. npm install primeng --save latest > 6.0.0

    3. npm install quill --save

    4. 编辑 angular.json。如果您的 angular.json 和 node_module 位于同一级别的树,请仔细更新。下面的编辑我是这样编辑的:

      “样式”:[ "src/styles.scss", “node_modules/quill/dist/quill.core.css”, “node_modules/quill/dist/quill.snow.css” ], “脚本”:[ “node_modules/quill/dist/quill.js” ]

    5. 将其导入您的模块:import {EditorModule} from 'primeng/editor';

      进口:[ Http模块, 表单模块, 浏览器模块, 按钮模块, 表模块, 编辑器模块 ],

    6. 在任意模板<p-editor [(ngModel)]="text1" [style]="{'height':'320px'}"></p-editor> <p>Value: {{text1||'empty'}}</p>中添加html

    7. 并在组件文件中为 text1 赋予一些值:字符串 text2: 字符串;

    Github repo 供参考Git

    【讨论】:

    • 哦! PrimeNG 对我来说工作得很好,只是编辑器模块不工作,其他模块(如 Toast 或按钮)工作得很好。
    • 您使用的是哪个版本的 PrimeNg?你有任何 plunker 或 stackbliz 演示吗?或 git hub 示例。因为在最新版本的 PrimeNg 中我没有明确安装 quell。
    • 它是“primeng”:“^6.1.2”。而且PrimeNG的官网显示需要对Quill有一个依赖(primefaces.org/primeng/#/editor)我不确定最新的PrimeNG版本是否带有Quill,但我不得不下载它。很抱歉,我没有这些可以给你看:(
    • ohhh!!...对不起,我为终端而不是编辑器创建了项目。我将尝试创建另一个并分享我的发现
    • 原来是模块的问题,有些东西没有让通用模块应用程序文件中的模块工作,所以我创建了一个模块应用程序文件,它现在可以工作了,谢谢你的帮助!我真的很感激!
    猜你喜欢
    • 1970-01-01
    • 2019-08-23
    • 2019-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    相关资源
    最近更新 更多