Hello, I am using the cordova file transfer plugin from ngCordova (both updated to last version) to download a file. I am running the app on android lolipop (lg g3)
I keep searching on my code and on google with no success.
The download is working well, but the problem is that the progress function is going slow.
To explain myself better: the success callback is executed before the progress stop running.
Also, I am using ionic tabs template, and it won’t load another tab (even with text only) before the download is finished.
I am not sure but I guess $timeout() should be executed in background and it looks it is not in my case. Here is my code, hope you can help me!
angular.module('starter.controllers', ['angular-svg-round-progress', 'ngCordova'])
.controller('SearchCtrl', function($scope, $http, $ionicLoading, $rootScope,$timeout, $cordovaFileTransfer, $ionicPlatform) {
$scope.download = function(id) {
$scope.hideDownload[id] = 1;
$ionicPlatform.ready(function() {
var url = "http://cdn.wall-pix.net/albums/art-space/00030109.jpg"
console.log('path: ' + cordova.file.applicationStorageDirectory);
var targetPath = cordova.file.applicationStorageDirectory + "testImage.png";
var trustHosts = true
var options = {};
$cordovaFileTransfer.download(url, targetPath, options, trustHosts)
.then(function(result) {
console.log('done');
console.log(result);
}, function(err) {
console.log('error');
console.log(err);
}, function (progress) {
$timeout(function () {
$scope.progress[id] = (progress.loaded / progress.total) * 100;
console.log(progress.loaded + ' / ' + progress.total);
})
});
});
}
})
PS: $scope.progress[id] only update some text
PS2: If progress function is empty then I don’t have freezing, and the file is still well downloaded. But if I set an empty $timeout() function then it freeze. Of course updating $scope.progress[id] without using $timeout also freeze.