javascript - how to use jquery file upload angular version? -


here how use angular jquery file upload

var album = angular.module('album', ['restangular', 'blueimp.fileupload']),  .controller('somecontroller',function($scope,){     $scope.options = {             }   }) 

all did set scope.options, change controller ,and magically works

setup jquery file upload seems quite easy, there confuse me

how can call jquery file upload's callback function. example, if files uploaded successfully,i want update ui calling fileuploaddone function ,it confuse me because there no added file in controller.

i'm new angularjs, please me understand workflow of angular jquery file upload

the blueimp.fileupload uses events fired via $emit 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 can add event listener in 1 of parent scope controllers, e.g.:

$scope.$on('fileuploadprocessdone', function(event, files){      $.each(files, function (index, file) {         //do want     }); }); 

you can override default handleresponse function in 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);             // want...         } else if (data.errorthrown || data.textstatus === 'error') {              data.files[0].error = data.errorthrown ||              data.textstatus;         }      };      }]); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -