Created
March 18, 2016 06:29
-
-
Save scuxiayiqian/26fea4d78dbeda3f2bee to your computer and use it in GitHub Desktop.
离开页面时取消定时器
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var promise; | |
// starts the interval | |
$scope.start = function() { | |
// stops any running interval to avoid two intervals running at the same time | |
$scope.stop(); | |
// store the interval promise | |
promise = $interval(getOrderList, 5000); | |
console.log("start"); | |
}; | |
// stops the interval | |
$scope.stop = function() { | |
$interval.cancel(promise); | |
console.log("cancel"); | |
}; | |
// starting the interval by default | |
$scope.start(); | |
$scope.$on('$destroy', function() { | |
$scope.stop(); | |
}); | |
function getOrderList() { | |
// get restaurant list request | |
$http({ | |
method: 'GET', | |
url: 'http://202.120.40.175:21104/order/unconfirmedorder', | |
crossDomain: true | |
}).success(function (orderArr) { | |
console.log("get all order list successed"); | |
$scope.rowCollection = orderArr; | |
$scope.displayedCollection = $scope.rowCollection; | |
}).error(function () { | |
console.log("get order list failed"); | |
}); | |
//202.120.40.175:21104/order/unconfirmedorder | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment