2016-03-07 45 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進步法的回調。