我想知道如何显示图像列表(通过拖放)。我已经有了拖放部分的指令。但是在我的应用程序中,我在哪里“解析” FileList 以及如何将数据从指令传递到部分?这是控制器的工作吗?
/**
* Adds drag&drop functionality to a div
* @Example: <div drop-target ng-class="{active:isHot}" class="dropzone">Drop here</div>
*/
angular.module('myApp.directives').
directive('dropTarget', function () {
return function ($scope, $element) {
// Drophandler passes a fileList to the controller
$element.bind('drop', function (evt) {
evt.stopPropagation();
evt.preventDefault();
// FileList should go to the controller/view
var fileList = evt.dataTransfer.files;
console.log(fileList);
$scope.$apply(function () {
$scope.imageList = fileList;
});
return false;
});
// DragOverHandler highlights the dropzone
$element.bind('dragover', function (evt) {
evt.stopPropagation();
evt.preventDefault();
$scope.isHot = true;
return evt.dataTransfer.dropEffect = "copy";
});
// DragOverHandler de-highlights the dropzone
$element.bind('dragleave', function (evt) {
evt.stopPropagation();
evt.preventDefault();
$scope.isHot = false;
});
};
})