timeout
The $timeout
service returns a promise that can be cancelled using $timeout.cancel()
$timeout
返回的是一个Promise,然后Promise可以被cancel
var app = angular.module('myapp', []);
app.controller('PopupCtrl', function($scope, $timeout){
var timer;
$scope.show = false;
$scope.mouseover = function(){
$timeout.cancel(timer);
$scope.show = true;
};
$scope.mouseout = function(){
timer = $timeout(function () {
$scope.show = false;
}, 2000);
};
});