how to use jquery file upload angular version?

夙愿已清 提交于 2019-12-02 23:51:28

the 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;
        }
     };     
}]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!