【发布时间】:2020-05-08 19:16:16
【问题描述】:
在我的 Angular 8 应用中使用 tinyMCE 并出现错误:
ReferenceError: tinymce is not defined
component.ts
declare const tinymce: any; // outside the class
ngAfterViewInit() { // inside the class
tinymce.init({
selector: 'tinymce',
height: 300,
menubar: false,
plugins: 'link lists paste image',
toolbar: 'undo redo | formatselect | bold italic backcolor link image | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat'
});
}
component.html
<editor #tinymce id="tinymce" apiKey="mykeyishere" formControlName="article"></editor>
我正在尝试从组件而不是模板调用 tinymce 上的 init(),因为我无法在模板中执行此操作(来自 official docs):
/* without images_upload_url set, Upload tab won't show up*/
images_upload_url: 'postAcceptor.php',
/* we override default upload handler to simulate successful upload*/
images_upload_handler: function (blobInfo, success, failure) {
setTimeout(function () {
/* no matter what you upload, we will turn it into TinyMCE logo :)*/
success('http://moxiecode.cachefly.net/tinymce/v9/images/logo.png');
}, 2000);
}
我需要在我的组件中定义自定义上传图像处理程序,但 TinyMCE Angular 的文档仅涵盖从模板调用 init 的用例,因此在处理图像上传时文档中没有解决方案。
我做错了什么?
【问题讨论】: