daydreamer
daydreamer

Reputation: 91949

How to hide a div after some time interval?

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?

Upvotes: 4

Views: 3896

Answers (2)

dting
dting

Reputation: 39287

$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.com/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>

Upvotes: 5

AJ Richardson
AJ Richardson

Reputation: 6810

You can use $timeout (a dependency you inject into your controller).

Example:

$scope.reportSent = true;
$timeout(function() {
    $scope.reportSent = false;
}, 2000);

Upvotes: 0

Related Questions