javascript - 如何在 ngx-ckeditor angular 7 中使用 insertText 方法
问题描述
我在我的项目中使用 angular 8 并且我正在尝试实现ngx-CKEditor。我需要在编辑器中添加自定义文本,当我单击列表时,我需要在 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
解决方案
尝试使用{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>
打字稿:
@ViewChild("myEditor", { static: false }) myEditor: any;
并像这样使用它:
this.myEditor.instance.insertText(value);
推荐阅读
- javascript - 如何在 React.js 中使用 JavaScript 修改 CSS
- python - PYTHON:如何抓取字符串的特定部分?
- bash - 如何防止 bash subshell 等待子进程
- reactjs - 重新加载页面 React 后显示 Facebook 评论插件
- python - 是否可以将流中的内容保存到变量而不是位置?
- swift - 传递为参数后如何保存模型?或作为函数获取?核心数据
- python - print() 结果不输出,找不到错误
- c# - DockPanel 的 IsEnabled 上的 WPF 绑定问题
- java - 为什么我在 Linkedlist 程序中获取 java.lang.IndexOutOfBoundsException 以打印 LinkedList 中连续的最大和最小数字
- javascript - 从本地文件夹导入 type=module 的脚本会导致 CORS 问题