繁体   English   中英

如何在 Angular 中的 Quill Js 编辑器中预填充数据

[英]How to Prefill Data Inside The Quill Js Editor In Angular

我在这里需要一点帮助。

在我的 angular 应用程序中,我从 api 获得了一些数据。

我想预填充我在 Quill Editor 输入框中获取的数据的值。 Quill Editor 不适用于 html value属性,因此这不起作用: [value]="paymentMessage? paymentMessage.message_before_payment: ''"

到目前为止,我只能将数据显示为占位符而不是实际值。 下面是我的代码:

 <quill-editor
            [styles]="editorStyle"
            name="form"
            [placeholder]="paymentMessage ? paymentMessage.message_before_payment : ''"
            [ngModelOptions]="{ standalone: true }"
 >
 </quill-editor>

这是我得到的结果: 在此处输入图像描述

如果我使用[innerHtml]属性。 数据将显示在输入字段外,而不是显示在输入字段内。

我真的很感激我能得到的任何帮助。

这是他们 npm 网站的链接。 https://www.npmjs.com/package/ngx-quill

嗨,我认为最好设置自定义值 component.ts 而不是 html。

像这样:

组件.html

  <ngx-quill #editor [(ngModel)]="content" [modules]="modules"  (contentChanged)="logChange($event);"></ngx-quill>

组件.ts

export class AppComponent {
  content='my text'

  titleName = 'Angular';
  modules = {
    toolbar: [      
      [{ header: [1, 2, false] }],
      ['bold', 'italic', 'underline'],
      ['image', 'code-block']
    ]
  };
}

我给你留了一个 stackbliz 的链接,以获得一些正在运行的解决方案示例;)。

https://stackblitz.com/edit/angular-quill-editor-15qhyp

带有一些不同示例的回购链接: https://github.com/KillerCodeMonkey/ngx-quill-example

在这里试试这个!

 @ViewChild('editorText') editorText:; QuillViewComponent: private content; any: ngAfterViewInit().{ this.content = '<p>return back-end</p> //fill this variable with what comes from your database this.editorText.content = this;content; }
 <quill-editor #editorText></quill-editor>

如何调整羽毛笔编辑器的大小以适应<div> ?</div><div id="text_translate"><p> 我希望羽毛笔编辑器自动适应父&lt;div&gt;元素。</p><p> 我创建了&lt;div&gt;元素,并在其中再次创建了一个&lt;div&gt;元素,该元素将成为 quill 编辑器的容器。 工具栏是自动创建的。 我使用 css 将父&lt;div&gt;元素的大小调整为width:50%和height:50% ,我希望其中的所有内容(羽毛笔编辑器和工具栏)都适合其中,但是羽毛笔编辑器的某些部分会出现父&lt;div&gt;元素的。</p><p> <strong>HTML:</strong></p><pre class="lang-html prettyprint-override"> &lt;,-- parent div element: in which quill editor should fit --&gt; &lt;div id="parent" style="width;50%:height;70%:border:2px solid green"&gt; &lt;!-- Quill editor div --&gt; &lt;div id="editor"&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> <strong>Javascript:</strong></p><pre> var tool = [[{ 'header': '1' }, { 'header': '2' }], [{ size: ['small', false, 'large', 'huge'] }], ['bold', 'italic', 'underline', 'strike'], [{ 'color': [] }, { 'background': [] }, { 'font': [] }, { 'align': [] }], ['image',]]; var option = { placeholder: 'Compose an epic...', theme: 'snow', modules: { toolbar: tool }, bounds:'#parent' }; var quill = new Quill('#editor', option);</pre><p> 我在父 div 周围放了一个绿色边框,我发现编辑器从边框出来了。 请看截图:</p><p> <a href="https://i.stack.imgur.com/RlASQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RlASQ.png" alt="截屏"></a></p><p> 注意:我只想保持父 div 的大小固定。 所以,请告诉我该怎么办?</p><p> 编辑:我将整个代码(html 文件)上传到我的服务器(<a href="http://tu.unaux.com/game.html" rel="nofollow noreferrer">这里</a>)。 问题仍然存在。 请检查一下,您可以使用“检查元素”查看整个代码。</p></div>

[英]How to resize quill editor to fit inside a <div>?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何用angular和js附加多个鹅毛笔编辑器 如何调整羽毛笔编辑器的大小以适应<div> ?</div><div id="text_translate"><p> 我希望羽毛笔编辑器自动适应父&lt;div&gt;元素。</p><p> 我创建了&lt;div&gt;元素,并在其中再次创建了一个&lt;div&gt;元素,该元素将成为 quill 编辑器的容器。 工具栏是自动创建的。 我使用 css 将父&lt;div&gt;元素的大小调整为width:50%和height:50% ,我希望其中的所有内容(羽毛笔编辑器和工具栏)都适合其中,但是羽毛笔编辑器的某些部分会出现父&lt;div&gt;元素的。</p><p> <strong>HTML:</strong></p><pre class="lang-html prettyprint-override"> &lt;,-- parent div element: in which quill editor should fit --&gt; &lt;div id="parent" style="width;50%:height;70%:border:2px solid green"&gt; &lt;!-- Quill editor div --&gt; &lt;div id="editor"&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> <strong>Javascript:</strong></p><pre> var tool = [[{ 'header': '1' }, { 'header': '2' }], [{ size: ['small', false, 'large', 'huge'] }], ['bold', 'italic', 'underline', 'strike'], [{ 'color': [] }, { 'background': [] }, { 'font': [] }, { 'align': [] }], ['image',]]; var option = { placeholder: 'Compose an epic...', theme: 'snow', modules: { toolbar: tool }, bounds:'#parent' }; var quill = new Quill('#editor', option);</pre><p> 我在父 div 周围放了一个绿色边框,我发现编辑器从边框出来了。 请看截图:</p><p> <a href="https://i.stack.imgur.com/RlASQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RlASQ.png" alt="截屏"></a></p><p> 注意:我只想保持父 div 的大小固定。 所以,请告诉我该怎么办?</p><p> 编辑:我将整个代码(html 文件)上传到我的服务器(<a href="http://tu.unaux.com/game.html" rel="nofollow noreferrer">这里</a>)。 问题仍然存在。 请检查一下,您可以使用“检查元素”查看整个代码。</p></div> nuxt.js中quill编辑器onkeyup的使用方法 Quill js 在编辑器中放置嵌入或 html 内容 Shadow DOM 中的 Quill 编辑器 如何将现有数据读入 Quill JS 如何为羽毛笔编辑器设置内容? 如何使用 React.js 用数据预填充 CkEditor? 页面加载时,Quill编辑器中的格式化文本 在 Quill 编辑器 Angular 中添加 fonts 2+
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM