我也为此苦苦挣扎。这个基本功能的当前文档真的很差。无论如何,这就是我的做法:
$scope.imageUpload = function(files) {
uploadEditorImage(files);
};
function uploadEditorImage(files) {
if (files != null) {
// Begin uploading the image.
// Here I'm using the ngFileUpload module (named 'Upload') to upload files, but you can use $.ajax if you want
// Remember to include the dependency in your Controller!
Upload.upload({
url: 'api/resources/upload-file',
file: files[0]
}).success(function(data, status, headers, config) {
// The image has been uploaded to your server.
// Now we need to insert the image back into the text editor.
var editor = $.summernote.eventHandler.getModule(),
uploaded_file_name = data.file_name, // this is the filename as stored on your server.
file_location = '/uploads/'+uploaded_file_name;
editor.insertImage($scope.editable, file_location, uplaoded_file_name);
});
}
};
要让图像重新显示在编辑器中,重要的部分在这里:
var editor = $.summernote.eventHandler.getModule(),
uploaded_file_name = data.file_name,
file_location = '/path-where-you-upload-your-image/'+uploaded_file_name;
editor.insertImage($scope.editable, file_location, uploaded_file_name);
$.summernote.eventHandler.getModule() 检索所有 Summernote 原生的 API methods。在这种情况下,您需要使用insertImage() 方法将上传的图片重新插入到编辑器中。
如果有人有任何更清洁的解决方案,请继续!