Ionic Framework在$ ionicLoading中显示动态值

时间:2016-03-07 20:21:53

标签: ionic-framework

如何在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&#39 ; s值反映了当前的下载进度。

3 个答案:

答案 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();
        }
    });

答案 1 :(得分:0)

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

我没有测试过,但是根据声明:

  

在使用新内容打开加载器时使用$ ionicLoading.show(),   它会更新内容。

如果您在.show()已经显示之后调用$ionicLoading,它应该更新内容..如果此功能实际上现在是Ionic的一部分,并且您进行某种循环和延迟例行公事,你应该能够实现你所追求的目标。

答案 2 :(得分:0)

您好我正在使用图片上传的显示百分比,如19%......

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

         });

其中 evt 是进度方法的回调。