I am trying to write an application in Angular which updates data like every 10 seconds. My problem is that the function is only being called once every time i refresh my page.
The console.log is just to ensure that the function is just being called once.
This is my code for initiating the interval:
var app = angular.module('myApp',['ngRoute', 'ui.bootstrap', 'ngNotify', 'ngTagsInput', 'djds4rce.angular-socialshare']);
app.run(function($FB, $http, $rootScope, $interval){
$FB.init('527807327395199');
$interval(function() {callAtInterval($http, $rootScope)}, 1000, true);
$rootScope.count = 0;
});
function callAtInterval($http, $rootScope) {
$http.get("/points-for-school")
.then(function(response){
$rootScope.schoolCompetitionPoints = response.data;
console.log($rootScope.count++);
console.log(response);
}, function(response){
console.error(response);
});
}
Is the problem that i do this in the app.run method?
Do i have to put the code into a controller for it to work?
If there is a way of making this work without creating a controller i would prefer it.