gpt4 book ai didi

angularjs - Angular js Div 仅显示 3 秒

转载 作者:行者123 更新时间:2023-12-03 13:22:09 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com