显示功能,同时从数据库获取数据的进度 [英] showing progressbar while function fetching data from database

查看:140
本文介绍了显示功能,同时从数据库获取数据的进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个按钮,点击一个按钮,我调用一个函数例如

I have a button on this button click I am calling a function e.g

<button ng-Click="getData()"></button>
<div class="Progressbar" ng-show=" showProgress "></div>

控制器:

$scope.showProgress = false;
$scope.getData = function () {
    $scope.showProgress = !$scope.showProgress;
    myRepository.getAllData();
}

此功能正在较长的时间从数据库中获取数据。结果
我想说明一个微调,而数据也越来越牵强。

This function is taking longer time to fetch data from Database.
I want to show a SPINNER while data is getting fetched.

但这个格显示全功能已经完成之后。
我希望它的功能完成之前显示。
我怎样才能做到这一点?

But this "Div" is shown only after whole function has been completed. I want it to be shown before the completion of function. How I can achieve that?

推荐答案

设置 showProgress = TRUE 加载数据前,和一旦数据被加载。对于可靠的行为让 myRepository.getAllData 回报的承诺,然后用它的然后方法来隐藏微调:

Set showProgress = true before loading data, and to false once data is loaded. For reliable behavior make myRepository.getAllData return promise, and then use its then method to hide spinner:

$scope.getData = function() {
    $scope.showProgress = true;
    myRepository.getAllData().then(function() {
        $scope.showProgress = false;
    });
}

这篇关于显示功能,同时从数据库获取数据的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆