我正在尝试为 plupload 创建一个指令。为了一次一步完成,我首先在不使用指令(控制器和标准 html)的情况下使文件上传工作。然后我添加了指令并成功地让 html 正确呈现。不幸的是,plupload 绑定随后中断了。
乍一看,在 plupload 进行绑定之前,该指令似乎没有呈现,但是如果我在代码中添加日志语句,该指令确实返回了哈希值,并且所有 html 元素似乎都存在于 DOM 中。
关于如何使这项工作的任何想法?
html
<div ng-controller="ProfilePhotoUploader">
This does not work
<uploader url="<%= profile_image_uploader_path %>"></uploader>
This works
<div id="profile-image-container">
<div id="select-file">Select File</div>
<div id="drop-area">Drop file here</div>
<button class="button small" ng-click="upload('<%= profile_image_uploader_path %>')">Upload File</button>
</div>
</div>
上传者.js
var uploader = angular.module('uploader', []);
uploader.directive('uploader', function () {
alert("in directive");
return {
restrict: 'E',
scope: {
url:'@'
},
templateUrl: "/assets/uploader.html"
}
});
资产/uploader.html
<div id="profile-image-container">
<div id="select-file">Select File</div>
<div id="drop-area">Drop file here</div>
<button class="button small" ng-click="upload('{{url}}')">Upload File</button>
</div>
profile_photo_uploader.js
var ProfilePhotoUploader = function ($scope) {
console.log($("uploader"));
$scope.uploader = new plupload.Uploader({
runtimes: "html5",
browse_button: 'select-file',
max_file_size: '10mb',
container: "profile-image-container",
drop_element: "drop-area",
multipart: true,
multipart_params : {
authenticity_token: $('meta[name="csrf-token"]').attr('content'),
_method: 'PUT'
},
filters: [
{title: "Image Files", extensions: "jpg,jpeg,png"}
]
});
$scope.upload = function(url) {
$scope.uploader.settings.url = url;
$scope.uploader.start();
};
$scope.uploader.init();
};