2016-03-07 36 views
2

如何在ionicLoading中显示动态值? 这里是我的代码显示$ionicLoading,这里的想法是,以显示下载进度:

$rootScope.updateProgress = 0; 
$ionicLoading.show({ 
    template: 'Updating...' + $rootScope.updateProgress 
}); 

,后来在我的代码更新$rootScope.updateProgress的价值:

var iPecent = Math.round(downloadProgress.receivedBytes/downloadProgress.totalBytes * 100); 
$rootScope.$apply(function() { 
    $rootScope.updateProgress = iPecent; 
}); 

然而,$rootScope.updateProgress的价值在屏幕上显示$ionicLoading时不反映 - 仅显示初始值0.如果我注销$rootScope.updateProgress的值,它将反映当前的下载进度。

+0

是否使用文件传输插件下载文件 –

+0

是的,先生,文件传输插件用于下载我的应用程序的更新。 –

回答

2

让我用cordova-plugin-file-transfer为例:

$ionicLoading.show({ 
     template: 'downloading...' 
    }); 
    $cordovaFileTransfer.download(source, filePath, options, trustAllHosts).then(function (result) { 
     console.log('download successfully!'); 
     $ionicLoading.hide(); 
    }, function (err) { 
     alert('download failed!' + err); 
    }, function (progress) { 
     var downloadProgress = (progress.loaded/progress.total) * 100; 
     $ionicLoading.show({ 
      template: "Downloaded:" + Math.floor(downloadProgress) + "%" 
     }); 
     if (downloadProgress >= 100) { 
      $ionicLoading.hide(); 
     } 
    }); 
+0

这适用于我!谢谢@汤姆。如果你打电话给'$ ionicLoadigng.show()'百次显示百分比变化,你有什么机会知道对应用程序的性能影响? –

0

我相信这是请求并在这里添加https://github.com/driftyco/ionic/issues/699

我没有测试过,但是基于声明:

使用$ ionicLoading.show(),而加载器是新内容开放, ,它会更新内容。

如果调用后续.show()$ionicLoading已经显示出,它应该更新内容。如果这个功能其实是在现在离子的一部分,你把某种循环和延时程序,你应该能够实现你的目标。

0

嗨,我使用像19%的图像上传的节目比例...

var progressPercentage = parseInt(100.0 * evt.loaded/evt.total); 
    $ionicLoading.show({ 
     template: 'Uploading Start....' + parseInt(100.0 * evt.loaded /evt.total) + '%', 

     }); 

其中EVT进步法的回调。