The Plunkr
http://plnkr.co/edit/6kpLplq5hy9e2sXMaEsG?p=preview
The HTML
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@*" data-semver="1.2.15" src="http://code.angularjs.org/1.2.15/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app="myApp" ng-controller="MyCtrl">
{{data.theDate}}
</body>
</html>
The JS
angular.module("myApp", []).service("UpdatingService", function($http, $timeout){
var service = {
data:{},
getData:function(){
$http.get("someData.json").success(function(result){
angular.copy(result, service.data)
service.data.theDate+=" "+new Date();
});
}
};
cancelRefresh = $timeout(function myFunction() {
service.getData();
cancelRefresh = $timeout(myFunction, 1000);
},1000);
return service;
}).controller("MyCtrl", function($scope, UpdatingService){
$scope.data = UpdatingService.data;
});
So I show how I would generally do this above. First create a service that handles doing the request and storing the data. Then make a controller and inject said service. Within the service inject the $http and $timeout services from angular so we can make the ajax request and can repeat the request thereby polling the server. Since there's no real setInterval the $timeout callback creates a new $timeout to continue the cycle, you can use the cancelRefresh if you need to stop the timer at some point details on that in the link below.
using setInterval in angularjs factory