我是 Angular js 的新手。我完成了 div 隐藏和显示。只是我想知道如何隐藏或显示 div 仅 3 秒。
在这里,我附上了我使用的代码。
html代码:
<div ng-hide="loginAlertMessage">Dynamic user feedback message comes here.</div>
<a ng-click="forgotPassword()">Forgot Password?</a>
Angular js代码:
$scope.loginAlertMessage = true;
$scope.forgotPassword = function () {
$scope.loginAlertMessage=false;
};
最佳答案
注入(inject) $timeout
service在 Controller 中并使用它来取消设置 loginAlertMessage
.
app.controller('MyController', ['$scope', '$timeout', function($scope, $timeout) {
$scope.loginAlertMessage = true;
$scope.forgotPassword = function() {
$scope.loginAlertMessage = false;
$timeout(function() {
$scope.loginAlertMessage = true;
}, 3000);
};
// ...
}]);
关于angularjs - Angular js Div 仅显示 3 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20489640/