我正在处理一个要求,我必须使用 quill-editor 添加和编辑内容,数据被存储到数据库中,这很好,但在再次保存后,我必须检索它以进行编辑。
我的问题:
在存储内容时,p 标签不会添加到内容中。我不知道如何解决它,我也是羽毛笔编辑器和角度的新手。我已经搜索了解决方案,但我找不到任何可行的解决方案所以来到这里。
羽毛笔编辑器 HTML:
<div>
<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>
<quill-editor [style.display]="'block'" (onEditorCreated)="onEditorCreated($event)" [style.height]="'400px'" formControlName="body" #description>
</quill-editor>
组件.ts
import { QuillEditorComponent } from 'ngx-quill';
export class EditMailTemplateComponent implements OnInit { @ViewChild('description') description: QuillEditorComponent;
public editor;
editForm() {
this.mailTemplateForm = this.fb.group({ id: 0, name: [''], body: [''], });
}
getFormData()
{
this.editForm();
this.mailTemplateForm.patchValue(this.data.form_data);
}
onEditorCreated(event) {
this.editor = event;
}
onSubmit()
{
this.mailTemplateForm.controls.body.setValue(this.editor.getText());
}
appendTagTo(textTOInsert: string)
{
textTOInsert = '{{'+textTOInsert+'}}';
const selection = this.editor.getSelection(true);
this.editor.insertText(selection.index, textTOInsert);
}
}
我在哪里做错了,是在将内容存储到数据库中还是在检索数据时?
谢谢你的帮助。