I have been trying to figure out how to update my $http json request at regular intervals and simultaneously update my bindings with the new data. I've come across examples using $timeout, but I haven't been successful in implementing it. I'm looking for the best approach to achieve this. Additionally, I am struggling to find a way to update the views with the newly fetched data.
Below is my current setup:
In the app.js file, I have the initial fetch for the json.
var myApp = angular.module('myApp', ['ngRoute']);
myApp.controller('MainCtrl', ['$scope', '$http',
function($scope, $http, $timeout) {
$scope.Days = {};
$http({
method: 'GET',
url: "data.json"
})
.success(function(data, status, headers, config) {
$scope.Days = data;
})
.error(function(data, status, headers, config) {
// something went wrong :(
});
}
]);
The HTML structure:
<ul ng-controller="MainCtrl">
<li class="date" ng-repeat-start="day in Days">
<strong>>{{ day.Date }}</strong>
</li>
<li class="item" ng-repeat-end ng-repeat="item in day.Items">
<strong>>{{ item.Name }}</strong>
</li>
</ul>