我在我的项目中使用了角8,我正在尝试实现ngx。我需要在编辑器中添加自定义文本,当我单击需要在CKEditor中添加内容的列表时,应该会出现这种情况。
我试过这段代码,但不适合我。
<ck-editor name="editor" #myEditor [(ngModel)]="editorValue" skin="moono-lisa" language="en" [fullPage]="true"></ck-editor>
<ul>
<li (click)="selectText('adasdasd1')">adasdasd1</li>
<li (click)="selectText('adasdasd2')">adasdasd2</li>
</ul>在ts文件中
public editorValue;
@ViewChild("editor", { static: true }) myEditor: any;单击ts文件中的事件
selectText(value) {
this.myEditor.instances.insertText(value);
}我收到一个错误:ERROR TypeError: Cannot read property 'instances' of undefined
发布于 2020-02-21 12:29:26
尝试与{static: false}一起使用
@ViewChild("editor", { static: false }) myEditor: any;false意味着它解析变化后检测。
更新:
您需要在.ts和.html (带有#符号的名称)文件中使用相同的名称:
HTML:
<ck-editor name="editor" #myEditor [(ngModel)]="editorValue"
skin="moono-lisa" language="en" [fullPage]="true"></ck-editor>TypeScript:
@ViewChild("myEditor", { static: false }) myEditor: any;像这样使用它:
this.myEditor.instance.insertText(value);https://stackoverflow.com/questions/60338613
复制相似问题