我正在尝试在ckeditor中添加图像。我参考了这份文件,并尝试了这样的操作
import { CKEditorComponent } from 'ngx-ckeditor';
ckeditorContent: any = '<p>Type here...</p>';
@ViewChild(CKEditorComponent) ckEditor: CKEditorComponent;
var url = "Some Image url"
let link = this.ckEditor.instance.document.createElement("img");
link.setAttribute("alt", "Image");
link.setAttribute("src", url);
this.ckEditor.instance.insertElement(link);
但是出现以下错误:
zone.js:192 Uncaught TypeError: Cannot read property 'instance' of undefined
at SafeSubscriber._next (about.component.ts:487)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:195)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:133)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:77)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:41)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at XMLHttpRequest.onLoad (http.js:1053)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
this.ckEditor显示为未定义。我也尝试过使用id但是却遇到了同样的错误。还有其他方法可以解决此问题