나는 이미지 목록을 표시하는 방법을 궁금합니다. 드래그 앤 드롭 부분에 대한 지침이 이미 있습니다. 하지만 내 응용 프로그램에서 "구문 분석"FileList 어떻게 부분에서 지시문에서 데이터를 전달합니까?이 작업은 컨트롤러에 있습니까?AngularJS : 이미지 목록을 표시하는 방법 (끌어서 놓기를 통해)
/**
* 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;
});
};
})
위의 코드에서 드래그 앤 드롭 한 파일 목록이 포함 된 변수를 알려주십시오. 그것은'fileList'입니까? – callmekatootie
그래, 파일 목록 – fabian
그럼 왜 '$ scope'에 묶지 않았 니? 지역 변수입니다 ... – callmekatootie