【问题标题】:ReferenceError: tinymce is not defined - Angular8ReferenceError:未定义tinymce - Angular8
【发布时间】: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 的用例,因此在处理图像上传时文档中没有解决方案。

我做错了什么?

【问题讨论】:

    标签: angular tinymce


    【解决方案1】:

    我在使用 Angular 10 时遇到了同样的问题。 我通过在 index.html 的头部添加这个脚本来修复它:

      <script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.4.2/tinymce.min.js"></script>
    
    

    我在这里找到了 src 链接:

    https://cdnjs.com/libraries/tinymce.

    关于信息,我正在使用 IntelliJ Ultimate。声明脚本后,IntelliJ 建议我下载脚本 src 库。 我希望这对将来的人有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-08-24
      • 2015-10-04
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多