基于true/false变量显示/隐藏进度条

Show/Hide Progress bar based on true/false variable

本文关键字:隐藏 变量 true false 基于 显示      更新时间:2023-09-26

我有一个简单的进度条,如下所示:

<div class="progress" ng-show="logging" id="login-progress">
    <div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
       Logging In...
    </div>
</div>

你会注意到我在第一个div上有一个ng-show="logging"。我想让这个show/hide基于true/false变量。

$scope.logging = false;
    authen.pass = function() {
        $scope.logging = true;
        $timeout(function(){
            ref.authWithPassword({
                email    : authen.email,
                password : authen.password
            }, function(error, authData) {
                if (error) {
                    $scope.logging = false; // This isn't working
                    swal({
                        title: "Whoops!",   
                        text: error,
                        timer: 4000,   
                        showConfirmButton: false
                    });
                } else {
                    $window.location.href = '#/dashboard';
                }
            });
        }, 2000);
    }

上面是我的控制器代码,默认情况下将日志变量设置为false。一旦函数被调用,它就会变为true。如果出现错误,则应将其设置为false。这似乎没有发生。

我在网上找到的所有东西都表明你就是这样做的。这个代码出了什么问题?

我试过把它从$timeout函数中删除,但仍然没有成功。

authWithPassword的回调很可能在角度摘要周期之外执行。它应该这样工作:

$scope.$apply(function() { $scope.logging = false });

也许这篇文章有助于理解它:理解Angular的$apply()和$digest()