如何在Summernote Editor(AngularJs版本)中上传图像?

时间:2016-02-24 18:19:01

标签: javascript angularjs file-upload summernote

有谁能告诉我如何在summernote编辑器中上传图像(angularJs v。)? 我的代码:

$scope.imageUpload = function(files) {
  uploadEditorImage(files);
};

function uploadEditorImage(files) {
  if (files != null) {
       Upload.upload({
          url: ROUTES.RESOURCESUPLOADFILE,
          file: files
      }).success(function(data, status, headers, config) {
         var uploaded_file_name = data.file_name,
         file_location = '/assets/uploads/'+uploaded_file_name;
         $scope.editor.summernote('editor.insertImage', uploaded_file_name);
       });
  }
};
   

 <summernote editor="editor" editable="editable" on-image-upload="imageUpload(files)"  ng-model="lessonFormEditData.description" ></summernote>

错误:

TypeError: Cannot read property 'summernote' of undefined

此外,“editable”参数返回undefined:

$scope.imageUpload = function(files) {
          console.log($scope.editable); // undefined
};

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要在成功后添加上述代码。

var uploaded_file_name = data.file_name;
var file_path = '/assets/uploads/'+uploaded_file_name;
var editor = $.summernote.eventHandler.getModule();
editor.insertImage(vm.editable, file_path, uploaded_file_name);