最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to hide a div after some time interval? - Stack Overflow

programmeradmin0浏览0评论

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?

Share Improve this question edited May 7, 2015 at 1:47 Robin Carlo Catacutan 13.7k12 gold badges54 silver badges86 bronze badges asked May 7, 2015 at 1:45 daydreamerdaydreamer 92.3k204 gold badges473 silver badges750 bronze badges
Add a ment  | 

2 Answers 2

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);
发布评论

评论列表(0)

  1. 暂无评论