如何一个接一个地显示登录错误消息

时间:2016-03-24 04:07:31

标签: angularjs

我应该检查我的登录是否有错误,它会显示“无效的用户名。然后,第二次登录将显示”服务器忙“,第三次登录将重定向到链接dashboard.html

但是,我的代码会忽略错误消息并继续使用dashboard.html。

我应该如何循环语句,以便相应地显示错误。

postData.data._class = postData.clazz;
        $timeout(function (data,status) {
          $scope.isLoading = false;
          if ($scope.hasError = false){

            $scope.errorMessage = "Invalid username or password. Error code = " + status;
            console.log($scope.errorMessage)
          }
         }, 2000);

         $timeout(function (data,status) {
           $scope.isLoading = false;
           if ($scope.hasError = true){

             $scope.errorMessage = "Server busy please try again later. Error code = " + status;
             console.log($scope.errorMessage)
           }
          }, 2000);

         $timeout(function (data,status) {
            $scope.isLoading = false;
            if ($scope.hasError = true){

               $window.location.href = "/dashboard.html";
            }
          }, 2000);

1 个答案:

答案 0 :(得分:0)

如果我的理解是正确的,那么当用户触发登录功能时,您希望得到3个不同的结果,错误情况可能是由于凭据无效或其他问题造成的。

如果这是正确的,那么您可以执行以下操作

您需要维护一个定义尝试的计数器。

git merge beta feature_a...alpha

请注意$scope.counter = 0; // This should be outside the event handler function $timeout(function (data,status) { $scope.isLoading = false; if ($scope.hasError){ if($scope.counter == 0) { $scope.errorMessage = "Invalid username or password. Error code = " + status; console.log($scope.errorMessage); $scope.counter++; } else if($scope.counter == 1) { $scope.errorMessage = "Server busy please try again later. Error code = " + status; console.log($scope.errorMessage); $scope.counter++; } else { $window.location.href = "/dashboard.html"; } } }, 2000); 是分配而非比较。

相关问题