,以顯示文件上傳進度條我使用這個指令如何使用angularjs
myApp.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
console.log(modelSetter)
element.bind('change', function(){
scope.$apply(function(){
modelSetter(scope, element[0].files[0]);
});
});
}
};
}]);
和我的服務是
myApp.service('fileUpload', ['$http', function ($http) {
this.uploadFileToUrl = function(file, uploadUrl){
var fd = new FormData();
fd.append('file', file);
$http.post(uploadUrl, fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function(){
})
.error(function(){
});
}
}]);
在我的控制器
$scope.uploadFile = function(){
var file = $scope.myFile;
console.log('file is ');
console.dir(file);
var uploadUrl = "/fileUpload";
fileUpload.uploadFileToUrl(file, uploadUrl);
};
我的問題是如何在將圖片上傳到網址時顯示進度條我JSfiddle URl https://jsfiddle.net/JeJenny/ZG9re/
得到類型錯誤不是一個函數 '類型錯誤:一個是不是function' –
@ User_3535在服務或控制器? – byteC0de
不知道,在angualr.js文件中出現錯誤, –