Ionic Interval error - TypeError: fn is not a function
Ionic Interval error - TypeError: fn is not a function
我的应用程序需要帮助。我尝试每 5 秒刷新一次函数。控制台显示 "TypeError: fn is not a function"。这是我的代码:
$scope.getItems = function (){
$http.get('http://example.com/script.php')
.success(function(res){
$scope.news = res;
})
.error(function(data, status) {
console.log("Error");
})
.finally(function(){
$scope.$broadcast('scroll.refreshComplete');
});
}
$scope.getItems();
$interval($scope.getItems(), 5000);
对于一个间隔,你必须传递函数,在这种情况下你直接执行函数并将 return 值传递给 $interval(未定义)。
因此,将您的代码更改为此,它应该可以工作! :)
$interval($scope.getItems, 5000);
我的应用程序需要帮助。我尝试每 5 秒刷新一次函数。控制台显示 "TypeError: fn is not a function"。这是我的代码:
$scope.getItems = function (){
$http.get('http://example.com/script.php')
.success(function(res){
$scope.news = res;
})
.error(function(data, status) {
console.log("Error");
})
.finally(function(){
$scope.$broadcast('scroll.refreshComplete');
});
}
$scope.getItems();
$interval($scope.getItems(), 5000);
对于一个间隔,你必须传递函数,在这种情况下你直接执行函数并将 return 值传递给 $interval(未定义)。
因此,将您的代码更改为此,它应该可以工作! :)
$interval($scope.getItems, 5000);