Damian Hetman Damian Hetman - 19 days ago 5
AngularJS Question

Ionic Interval error - TypeError: fn is not a function

I need help with my app. I tried to refresh function every 5 seconds. Console shows "TypeError: fn is not a function". This is my code:

$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);

Answer

For an interval, you have to pass the function, in this case your executing the function directly and pass the return value to $interval (which is undefined).

So change your code to this and it should work! :)

 $interval($scope.getItems, 5000);
Comments