admin管理员组文章数量:1200343
here is how I use angular jquery file upload
var album = angular.module('album', ['restangular', 'blueimp.fileupload']),
.controller('somecontroller',function($scope,){
$scope.options = {
something
}
})
all I did was set the scope.options, change the controller ,and everything just magically works
setup the jquery file upload seems quite easy, but there are something really confuse me
how can I call the jquery file upload's callback function. for example, if the files uploaded successfully,I want to update the ui by calling fileuploaddone function ,it confuse me because there is no added file in my controller.
I'm new to angularJS, please help me to understand the workflow of angular jquery file upload
here is how I use angular jquery file upload
var album = angular.module('album', ['restangular', 'blueimp.fileupload']),
.controller('somecontroller',function($scope,){
$scope.options = {
something
}
})
all I did was set the scope.options, change the controller ,and everything just magically works
setup the jquery file upload seems quite easy, but there are something really confuse me
how can I call the jquery file upload's callback function. for example, if the files uploaded successfully,I want to update the ui by calling fileuploaddone function ,it confuse me because there is no added file in my controller.
I'm new to angularJS, please help me to understand the workflow of angular jquery file upload
Share Improve this question asked Jul 22, 2013 at 7:41 paynestrikepaynestrike 4,65814 gold badges48 silver badges71 bronze badges1 Answer
Reset to default 25the blueimp.fileupload uses events that are fired via $emit to notify parent scopes:
on([
'fileuploadadd',
'fileuploadsubmit',
'fileuploadsend',
'fileuploaddone',
'fileuploadfail',
'fileuploadalways',
'fileuploadprogress',
'fileuploadprogressall',
'fileuploadstart',
'fileuploadstop',
'fileuploadchange',
'fileuploadpaste',
'fileuploaddrop',
'fileuploaddragover',
'fileuploadchunksend',
'fileuploadchunkdone',
'fileuploadchunkfail',
'fileuploadchunkalways',
'fileuploadprocessstart',
'fileuploadprocess',
'fileuploadprocessdone',
'fileuploadprocessfail',
'fileuploadprocessalways',
'fileuploadprocessstop'
].join(' '), function (e, data) {
if ($scope.$emit(e.type, data).defaultPrevented) {
e.preventDefault();
}
})
That means that you can simply add an event listener in one of the parent scope controllers, e.g.:
$scope.$on('fileuploadprocessdone', function(event, files){
$.each(files, function (index, file) {
//do what you want
});
});
You can also override the default handleResponse function in your config phase, e.g.:
angular.module('myApp', ['blueimp.fileupload']).
.config(['fileUploadProvider', function (fileUploadProvider){
fileUploadProvider.defaults.handleResponse = function (e,data){
var files = data.result && data.result.files;
if (files) {
data.scope().replace(data.files, files);
// do what you want...
} else if (data.errorThrown || data.textStatus === 'error') {
data.files[0].error = data.errorThrown ||
data.textStatus;
}
};
}]);
本文标签: javascripthow to use jquery file upload angular versionStack Overflow
版权声明:本文标题:javascript - how to use jquery file upload angular version? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738612458a2102711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论