Skip to content

Instantly share code, notes, and snippets.

@scuxiayiqian
Created March 18, 2016 06:29
Show Gist options
  • Save scuxiayiqian/26fea4d78dbeda3f2bee to your computer and use it in GitHub Desktop.
Save scuxiayiqian/26fea4d78dbeda3f2bee to your computer and use it in GitHub Desktop.
离开页面时取消定时器
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