<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.5秒后使用angular(无DOM操作)隐藏 div ?
动画如何以透明方式显示和隐藏?
答案 0 :(得分:1)
您可以使用下面的$timeout service:
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;