angularjs显示动画为真,并在延迟后隐藏

时间:2016-06-15 20:22:34

标签: javascript jquery html css angularjs

<div ng-show="IsError">ERROR !!</div>
<button ng-click="validate()">Validate</button>
function MainController($scope, ) {
    $scope.IsError = false;

    $scope.validate = function (val) {
        $scope.IsError = true;
        setTimeout(function () {
            $scope.IsError = false;
        }, 1500);
    }
}

在验证() div 上显示但不隐藏。

  1. 如何在1.5秒后使用angular(无DOM操作)隐藏 div

  2. 动画如何以透明方式显示和隐藏?

1 个答案:

答案 0 :(得分:1)

您可以使用下面的$timeout service

&#13;
&#13;
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope,$timeout) {
  $scope.IsError = false;

    $scope.validate = function (val) {
        $scope.IsError = true;
        $timeout(function () {
            $scope.IsError = false;
        }, 1500);
    }
  });
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-show="IsError">ERROR !!</div>
<button ng-click="validate()">Validate</button>
</div>
&#13;
&#13;
&#13;