如何在一段时间间隔后隐藏div?

day*_*mer 4 javascript angularjs

代码是

    <div class="sendStatus" ng-if="reportSent">
      <span data-icon="ok"></span> 
      {{progressStatus}}
    </div>
Run Code Online (Sandbox Code Playgroud)

这个想法是在发送报告时显示这个div,意思reportSent是真的.现在我想在2 seconds发言之后隐藏这个潜水.我该怎么办?

DTi*_*ing 5

$timeout 可以用来在延迟后隐藏div

var app = angular.module('app', []);

app.controller('myController', function($scope, $timeout) {
  $scope.sendReport = function() {
    $scope.reportSent = true;
    $timeout(function() {
      $scope.reportSent = false;
    }, 2000);
  };
});
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)