我在 Angular 7 中使用 ngx-editor。单击参数列表中的参数时,我需要在光标位置插入 html。附件是我当前视图的图像。现在点击参数,它就是以这种方式附加它,如图所示。
我希望每个选定的参数都是单独的徽章,应该在单个退格键中删除。此外,您还应该能够编写纯文本。
这就是我现在正在做的事情。
<div class="bm-link-btn pull-right mt-10" [tooltip]="tooltipTemplate" placement="bottom" >
Parameters </div>
<ng-template #tooltipTemplate>
<div class="u-display-flex text-left">
<div class="p20" *ngFor="let item of paramsList$|async as params">
{{item?.category}}
<div class="bm-link-btn" *ngFor="let param of item.parameters">
<span (click)="onClickOfParams(param.value)">{{param.displayName}}
</span>
</div>
</div>
</div>
</ng-template>
onClickOfParams(value) {
document.getElementById('ngx-editor-textarea').focus();
let html = `
<div class="parameter-item"><div class="badge-plain-new">`+ value + `</div></div>`;
if (!document.execCommand("InsertInputText", false, '')) {
document.execCommand("InsertHTML", false, html);
}
}
这就是我想要实现的。谁能告诉一个更好的方法来做到这一点?