【发布时间】:2016-03-12 02:53:24
【问题描述】:
我正在使用基于这个答案的方法:Server polling with AngularJS
但是当我有多个轮询方法时如何设置此更新?
这是我的服务的 sn-p:
function pollingService($resource) {
return {
methodA: $resource(window.rootUrl + 'api/methodA', { para: '@para1' }, {
query: { method: 'GET', params: {}, isArray: false }
}),
methodB: $resource(window.rootUrl + 'api/methodB', {}, {
query: { method: 'GET', params: {}, isArray: false }
})
}
};
那么如何设置 tick 方法来轮询这 2 个方法并且只创建 1 个轮询循环?
(function tick() {
$scope.method1 = pollingService.methodA.query(function () {
$timeout(tick, $scope.refreshRate);
});
$scope.method2 = pollingService.methodB.query(function () {
$timeout(tick, $scope.refreshRate);
});
})();
【问题讨论】:
标签: javascript angularjs ngresource