如何取消cordova的下载?

时间:2016-12-19 05:30:12

标签: angularjs cordova ionic-framework cordova-plugins

我正在使用$cordovafiletransfer.download()方法进行下载。我想知道如何在下载过程中取消下载。我在这里提到了我的代码:

 $scope.fileDownload = function(url) {

        $cordovaToast.showLongBottom('Your download has started');
        $scope.progressbar={"display":"block"};
        $scope.progressvalue=2;
        $scope.downloadbtn="downloadbtnon"

        var filename = url.split("/").pop();

        var targetPath = cordova.file.externalRootDirectory + 'Podcasts' + filename;

        $scope.loading = "font-size:20px;display:inline-block;stroke:#fff;";
        $scope.isDisabled = true;
        $cordovaFileTransfer.download(url, targetPath, {}, true).then(function(result) {
            //console.log('Success');
            $scope.hasil = 'Save file on ' + targetPath + ' success!';
            $scope.mywallpaper = targetPath;
            $scope.isDisabled = false;
            $scope.loading = "display:none;";
            $scope.progressbar={"display":"none"};
            $scope.downloadbtn="downloadbtnoff"
            // $timeout(function() {

            // }, 1000);
            $cordovaToast.showLongBottom('Download completed(' + targetPath + ')');
        }, function(error) {
            console.log('Error downloading file');
            console.log(error);
            $scope.hasil = 'Error downloading file...';
            $cordovaToast.showLongBottom('Download failed.. Please try again');
            $scope.progressbar={"display":"none"};
            $scope.downloadbtn="downloadbtnoff"
            $timeout(function() {
                $scope.isDisabled = false;
                $scope.loading = "display:none;";
            }, 1000);
        }, function(progress) {
            console.log('progress');
            $scope.downloadProgress = (progress.loaded / progress.total) * 100;
            $scope.progressvalue=$scope.downloadProgress;
            $scope.progressbar={"display":"block"};
            $scope.downloadbtn="downloadbtnon"
            // var downcountString = $scope.downloadProgress.toFixed();
            // console.log('downcountString');
            // $scope.downloadCount = downcountString;
        });
    }

取消下载我试过$cordovaFileTransfer.abort();,但收到Type error undefined not defined这样的错误。请任何人帮我解决这个问题。

0 个答案:

没有答案