Angular Ng文件上传模型:中止功能不起作用

时间:2016-02-18 10:59:18

标签: javascript angularjs ng-file-upload

我使用了以下模块https://github.com/danialfarid/ng-file-upload,除了中止上传过程外,它已有详细记录。在上传文件期间,取消上传的代码无效。 我得到的错误是“中止不是一种功能”。我不知道如何应用abort()函数来取消上传过程。

我不知道我在这里想念的是什么,有谁可以给​​我一些关于为什么的想法?或任何建议。

我的HTML

<body ng-app="fileUpload" ng-controller="MyCtrl">
     <h4>Upload on file select</h4>

    <button ngf-select="uploadFiles($files)" multiple 
            accept="image/*,audio/*,video/*">Select Files</button>

    <span class="progress" ng-show="progress >= 0">
        <div style="width:{{progress}}%" ng-bind="progress + '%'"></div>
    </span>
    {{errorMsg}}

    <button ng-click="cancelUpload()">Cancel</button>

</body>

JS(角)

var app = angular.module('fileUpload', ['ngFileUpload']);

app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {

var upload = "";

    $scope.uploadFiles = function (files) {
        $scope.files = files;
        if (files && files.length) {
            upload = Upload.upload({
                url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
                data: {
                    files: files
                },
                resumeSize: function() {return promise;}
            }).then(function (response) {
                $timeout(function () {
                    $scope.result = response.data;
                });
            }, function (response) {
                if (response.status > 0) {
                    $scope.errorMsg = response.status + ': ' + response.data;
                }
            }, function (evt) {
                $scope.progress = 
                    Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
            });
        }
    };


    $scope.cancelUpload = function(files){   // here is my cancel program
    console.log("Cancelling");
     upload.abort();              // this 'abort()' is not working as mentined
    }

0 个答案:

没有答案