In Directly,I want remove the files in the uploader,I did this

 $scope.close = function() {
        console.log($scope);
        $scope.isOpen = false;
        $('.file_container').empty();
        **angular.forEach($scope.uploader.files, function(v, k) {
            $scope.uploader.removeFile(v);
            $scope.fileLength = $scope.uploader.files.length;
        });**

    };

    $scope.uploader = new plupload.Uploader({
        runtimes: 'html5,html4',
        browse_button: 'addFile',
        max_file_size: '20000mb',
        chunk_size: '512kb',
        // resize: { width: 125, height: 85, quality: 90 },
        flash_swf_url: '../scripts/lib/plupload.flash.swf',
        filters: [{
                extensions: 'jpg,png'
            }]
    });

    $scope.fileLength = 0;
    $scope.currentUpload = 0;
    $scope.uploader.bind('init', function() {
        console.log('init');
    });
    $scope.uploader.bind('UploadProgress', function(up, files) {
        $('.progress_percent').eq($scope.currentUpload).html(files.percent + '%');
        $('.progress_bar').eq($scope.currentUpload).css('width', files.percent + '%');
    });
    $scope.uploader.bind('FilesAdded', function(up, files) {
        $scope.$apply(function() {
            $scope.fileLength = files.length;
        });
        console.log($('input[type=file]'));
        readURL($('input[type=file]')[0]);
    //    up.start();
    });
    $scope.uploader.bind('BeforeUpload', function(up, file) {
        var mediaName = 'MediaBank' + Math.random().toString().substr(2);
        up.settings.url = '/Upload.ashx?medianame=' + mediaName + '&activityid=2013';
    });
    $scope.uploader.bind('FileUploaded', function(up, file, info) {
        $scope.currentUpload++;
        console.log($scope.currentUpload);
    });
    $scope.uploader.init();
    $('#save').bind('click', function() {
        $scope.uploader.start();
    });

And,when I add 2 files,and when the "$scope.close" function was called,only 1 file was removed...why? thanks all of you !

有帮助吗?

解决方案

Might be an issue with the iterator and the fact you are changing the list as you browse it.

You may try to replace :

**angular.forEach($scope.uploader.files, function(v, k) {
            $scope.uploader.removeFile(v);
            $scope.fileLength = $scope.uploader.files.length;
        });**

with :

$scope.uploader.splice(0); // $scope.uploader.splice(); should work too
$scope.fileLength = $scope.uploader.files.length;

Hope this will help

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top