我正在研究一个要求,我必须将数据附加到一个容器中,该容器是 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 内的任何位置(或者如果光标在起点的编辑器中不存在)。任何帮助,将不胜感激。谢谢。