I am trying to find a solution on the Internet to be able to update my http json http request for a set time interval and at the same time update my bindings with new data.
I saw a few examples using $ timeout, but couldn't get it working and just wanted to find out what is the best approach for this. Also, the ability to update views with new data is reset, I canβt decide, because I couldnβt fulfill the new request.
Here is my current build.
app.js, this just shows the initial selection for 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) {
HTML setup:
<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>
source share