This used to work for me all the time using $scope.$apply on $http requests, what am i missing on this one? I first got the "Digest cycle is already in progress" msg, than added the setTimeout() which got rid of that msg but still ng-repeat wont update with the data. This shouldn't be a problem, i am clearly missing something.
The HTML:
<form name="userDataForm" role="form" ng-submit="submit()">
<input type="text" name="userId" placeholder="Enter User ID" ng-model="viewModel.useId" />
<input type="text" name="start" placeholder="Start Date: dd-mm-yyyy" ng-model="viewModel.startDate"/>
<input type="text" name="end" placeholder="End Date: dd-mm-yyyy" ng-model="viewModel.endDate"/><br/>
<button type="submit">
Get Data
</button>
<ul ng-repeat="place in viewModel.userData.data.significant_places">
<li>
You have been at <span style="color:red;">{{place.name}}</span> <span style="color:red;">{{place.number_of_days}}</span> days this month
</li>
<ul>
The JS
$scope.viewModel = {
userId:'',
startDate:'',
endDate:'',
userData:{}
};
$scope.submit = function(){
setTimeout(function(){
$scope.$apply(function(){
$http.get('http://localhost:3000/?user_id=279&start=20150101&end=20150113').success(function(data){
$scope.viewModel.userData = data;
}).error(function(){
console.log('error');
});
});
}, 1)
};