Angular js Div仅显示3秒

时间:2013-12-10 08:39:40

标签: angularjs

我是角度js的新手。我完成了div hide和show。只是我想知道如何隐藏或显示div仅3秒。 在这里我附上了我用过的代码。

html代码:

<div ng-hide="loginAlertMessage">Dynamic user feedback message comes here.</div>    
<a ng-click="forgotPassword()">Forgot Password?</a>

angular js code:

$scope.loginAlertMessage = true;

    $scope.forgotPassword = function () {
         $scope.loginAlertMessage=false;    
    };

2 个答案:

答案 0 :(得分:37)

在控制器中注入$timeout service并使用它取消设置loginAlertMessage

app.controller('MyController', ['$scope', '$timeout', function($scope, $timeout) {
   $scope.loginAlertMessage = true;

   $scope.forgotPassword = function() {
      $scope.loginAlertMessage = false;
      $timeout(function() {
         $scope.loginAlertMessage = true;
      }, 3000);
   };

   // ...
}]);

答案 1 :(得分:0)

注入$timeout服务(从setTimeout(function() {"action",time(in ms) })派生到控制器中,如果希望显示make div为true,如果希望隐藏,请使用此服务停止。