我正在满足一项要求,即我必须将数据附加到一个有角度的羽毛笔编辑器容器的容器中。我尝试了不同的方法,但是它们都不起作用。
我在下面尝试过
Try-1
this.mailTemplateForm.controls['body'].patchValue(value)
Try-2
this.mailTemplateForm.controls.body.setValue(value);
然后,现有数据将被新数据替换。有什么解决方案。
component.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
}
component.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>
我希望将数据添加到鹅毛笔编辑器(或)中出现的任何光标处,如果光标不在编辑器的起点处。任何帮助,将不胜感激。谢谢。
答案 0 :(得分:0)
希望这对某人有帮助。我已经通过注册羽毛笔编辑器的“ onEditorCreated()”方法解决了该问题,如下所示:
<quill-editor [style.display]="'block'" [modules]="editorOptions.editor"
(onEditorCreated)="onEditorCreated($event)" [style.height]="'300px'" formControlName="body" #description>
</quill-editor>
component.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);
}
}