angular - 将数据附加到羽毛笔编辑器现有数据角度
问题描述
我正在研究一个要求,我必须将数据附加到一个容器中,该容器是 Angular 中的 quill-editor 容器。我尝试了不同的东西,但它们都不起作用。
我在下面试过:
试一试
this.mailTemplateForm.controls['body'].patchValue(value)
尝试2
this.mailTemplateForm.controls.body.setValue(value);
然后现有数据将被新数据替换。有什么解决方案。
组件.ts:
import { QuillEditorComponent } from 'ngx-quill';
export class EditMailTemplateComponent implements OnInit {
@ViewChild('description') description: QuillEditorComponent;
mailTemplateForm: FormGroup;
ngOnInit() {
this.getFormData();
}
editForm(){
//console.log('test',this.data);
this.mailTemplateForm = this.fb.group({
id: 0,
name: [''],
slug: [''],
status: [''],
subject: [''],
body: [],
body_parameters: [''],
});
}
getFormData(){
-----------
-----------
this.editForm();
this.mailTemplateForm.patchValue(this.data.form_data);
}
appendTagTo(value: any){
console.log('called - ',value);
this.mailTemplateForm.controls.body.setValue(value); // Tried here
}
组件.html
<ul class="list-style-none mt-0">
<li *ngFor="let field of fieldList" class="py-4 text-uppercase">
<a color='accent' class='cursor-pointer' (click)="appendTagTo(field.field_name)"> {{ field.label_name }}
</a>
</li>
</ul>
<div fxFlex="75" class="mt-12">
<quill-editor [style.display]="'block'" [style.height]="'400px'" formControlName="body" #description>
</quill-editor>
</div>
我希望将数据添加到光标出现在 quill-editor 内的任何位置(或者如果光标在起点的编辑器中不存在)。任何帮助,将不胜感激。谢谢。
解决方案
希望这可以帮助某人。我已经通过使用注册 quill-editor 的 'onEditorCreated()' 方法解决了这个问题,如下所示:
<quill-editor [style.display]="'block'" [modules]="editorOptions.editor"
(onEditorCreated)="onEditorCreated($event)" [style.height]="'300px'" formControlName="body" #description>
</quill-editor>
组件.ts:
public editor;
onEditorCreated(event) {
this.editor = event;
}
appendTagTo(textTOInsert: string) {
if(textTOInsert){
textTOInsert = '{{'+textTOInsert+'}}';
const selection = this.editor.getSelection(true);
this.editor.insertText(selection.index, textTOInsert);
//this.editor.insertHTML(selection.index, textTOInsert);
}
}
推荐阅读
- javascript - Javascript-实时验证电话号码
- flutter - Flutter 两个关于 setState() 的代码的区别
- image - 小波域中的图像增强
- google-maps - 谷歌地图基准 - 澳大利亚
- python-3.x - 如何根据前缀拆分我的数据框值
- sql - 根据另一列的值条件在 SQL 中添加/选择多个列
- javascript - 如何使用数组过滤对象数组
- c# - OOxml 或 Office OpenXML C# - 从 DataTable 导出到 excel 布尔数据类型导致修复 excel
- javascript - 链接时如何使用 JS 承诺?
- mongodb - 如何在不使用 $unwind 的情况下加快聚合查询,包括数组中的日期字符串比较?