javascript - Ionic - Cordova - $cordovaFileTransfer freezes - slow - blocks tabs -
i using cordova file transfer plugin ngcordova (both updated last version) download file. running app on android lolipop (lg g3)
i keep searching on code , on google no success.
the download working well, problem progress function going slow. explain myself better: success callback executed before progress stop running.
also, using ionic tabs template, , won't load tab (even text only) before download finished.
i not sure guess $timeout() should executed in background , looks not in case. here code, hope can 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] update text
ps2: if progress function empty don't have freezing, , file still downloaded. if set empty $timeout() function freeze. of course updating $scope.progress[id] without using $timeout freeze.
Comments
Post a Comment