我想在简单的轮询循环中从休息服务中重新检索数据。我正在进行更新,但数据更改未反映在我的页面上。以下是我的代码段
function HomeController ($scope,CodeCampYear) {
$scope.faqs = faqs;
$scope.value = 0;
function pollData () {
CodeCampYear.fetchAll().then(function(data){
$scope.value += 1;
$scope.codecampyear = data[0];
$scope.codecampyear.liveFeedTitle = $scope.value;
});
setTimeout(pollData, 1000 * 5)
}
pollData();
...
答案 0 :(得分:0)
使用$timeout service进行$apply
:
function HomeController ($scope,CodeCampYear, $timeout) {
$scope.faqs = faqs;
$scope.value = 0;
function pollData () {
CodeCampYear.fetchAll().then(function(data){
$scope.value += 1;
$scope.codecampyear = data[0];
$scope.codecampyear.liveFeedTitle = $scope.value;
});
$timeout(pollData, 1000 * 5)
}
pollData();
...
使用$timeout
将允许Angular进入摘要循环并在触发setTimeout
循环后更新数据(第二次更新)。