【问题标题】:tinymce angular image picker syntaxtinymce 角度图像选择器语法
【发布时间】:2020-11-03 02:52:16
【问题描述】:

我有一个使用 angular 的 ionic 应用程序,我想将图像选择器放入我在页面上介绍的 tinymce 编辑器中。

在 tinymce docs 中,据我所知,它说要在 html 文件中使用 angular 指令(我还使用了来自 herengModel):

 <h1>TinyMCE 5 Angular Demo</h1>
 <editor
   [(ngModel)]="dataModel"
   [init]="{
     height: 500,
     menubar: false,
     plugins: [
       'advlist autolink lists link image charmap print preview anchor',
       'searchreplace visualblocks code fullscreen',
       'insertdatetime media table paste code help wordcount'
     ],
     toolbar:
       'undo redo | formatselect | bold italic backcolor | \
       alignleft aligncenter alignright alignjustify | \
       bullist numlist outdent indent | removeformat | help'
   }"
 ></editor>

一切正常,但现在我想添加一个图像选择器,但docs for that 暗示在 ts 文件中使用 js,如下所示:

tinymce.init({
  selector: 'textarea',  // change this value according to your HTML
  file_picker_callback: function(callback, value, meta) {
    // Provide file and text for the link dialog
    if (meta.filetype == 'file') {
      callback('mypage.html', {text: 'My text'});
    }

    // Provide image and alt text for the image dialog
    if (meta.filetype == 'image') {
      callback('myimage.jpg', {alt: 'My alt text'});
    }

    // Provide alternative source and posted for the media dialog
    if (meta.filetype == 'media') {
      callback('movie.mp4', {source2: 'alt.ogg', poster: 'image.jpg'});
    }
  }
});

我现在有点卡住了,因为我需要从 html 中的指令调用 file_picker_callback,但我似乎不知道怎么做。

另外,我认为我可以从 js/ts 文件而不是 html 文件中引用 ngModel,但我又有点卡住了,因为我不确定要查找什么。

我已经开始阅读 angular 文档以了解正在发生的事情(以及要做什么),但是朝着正确的方向进行一些指导不会出错。

【问题讨论】:

    标签: javascript angular ionic-framework tinymce angular-directive


    【解决方案1】:

    其实很简单,在html文件中使用this关键字即可:

    file_picker_callback: this.filePickerCallback
    

    然后在打字稿文件中创建函数filePickerCallback

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-11
      • 2014-07-22
      • 2016-04-26
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多