admin管理员组文章数量:1022997
The code is
<div class="sendStatus" ng-if="reportSent">
<span data-icon="ok"></span>
{{progressStatus}}
</div>
The idea is show this div when the report is sent, meaning reportSent
is true. Now I would also like to hide this dive after 2 seconds
lets say. How to I do that?
The code is
<div class="sendStatus" ng-if="reportSent">
<span data-icon="ok"></span>
{{progressStatus}}
</div>
The idea is show this div when the report is sent, meaning reportSent
is true. Now I would also like to hide this dive after 2 seconds
lets say. How to I do that?
2 Answers
Reset to default 5$timeout
can be used to hide the div after a delay
var app = angular.module('app', []);
app.controller('myController', function($scope, $timeout) {
$scope.sendReport = function() {
$scope.reportSent = true;
$timeout(function() {
$scope.reportSent = false;
}, 2000);
};
});
<script src="https://ajax.googleapis./ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<div ng-app='app' ng-controller='myController'>
<button ng-click="sendReport()">send report</button>
<div class="sendStatus" ng-if="reportSent">Report Sent</div>
</div>
You can use $timeout
(a dependency you inject into your controller).
Example:
$scope.reportSent = true;
$timeout(function() {
$scope.reportSent = false;
}, 2000);
The code is
<div class="sendStatus" ng-if="reportSent">
<span data-icon="ok"></span>
{{progressStatus}}
</div>
The idea is show this div when the report is sent, meaning reportSent
is true. Now I would also like to hide this dive after 2 seconds
lets say. How to I do that?
The code is
<div class="sendStatus" ng-if="reportSent">
<span data-icon="ok"></span>
{{progressStatus}}
</div>
The idea is show this div when the report is sent, meaning reportSent
is true. Now I would also like to hide this dive after 2 seconds
lets say. How to I do that?
2 Answers
Reset to default 5$timeout
can be used to hide the div after a delay
var app = angular.module('app', []);
app.controller('myController', function($scope, $timeout) {
$scope.sendReport = function() {
$scope.reportSent = true;
$timeout(function() {
$scope.reportSent = false;
}, 2000);
};
});
<script src="https://ajax.googleapis./ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<div ng-app='app' ng-controller='myController'>
<button ng-click="sendReport()">send report</button>
<div class="sendStatus" ng-if="reportSent">Report Sent</div>
</div>
You can use $timeout
(a dependency you inject into your controller).
Example:
$scope.reportSent = true;
$timeout(function() {
$scope.reportSent = false;
}, 2000);
本文标签: javascriptHow to hide a div after some time intervalStack Overflow
版权声明:本文标题:javascript - How to hide a div after some time interval? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745514622a2153982.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论