Saif Asif Saif Asif - 1 month ago 8
AngularJS Question

ng-repeat with http.get not updating

I have a simple

http.get
call in my controller as below

$scope.data = {};
$scope.data.displayBean = {};
$scope.fetchEventDetails = function() {
$http.get('http://localhost:8080/api/v1/event_details?eventId=' + $scope.data.selectedEventId)
.then(function(theEvent){
$scope.data.displayBean = theEvent;
});
};


And in my view I have used
ng-repeat
like below

<div class="list-group" data-ng-controller="MainCtrl">
<a href="#" class="list-group-item" ng-repeat="(key,val) in data.displayBean">
<h5 class="list-group-item-heading">{{key}}</h5>
<p class="list-group-item-text">{{val}}</p>
</a>
</div>


But it doesn't seem to update the view even though I get the reponse from the API call when I log it to the console.

Anything I am missing here ?

Answer
$scope.data = {};
$scope.data.displayBean = {};
$scope.fetchEventDetails = function() {
  $http.get('http://localhost:8080/api/v1/event_details?eventId=' + $scope.data.selectedEventId)
    .then(function(theEvent){
      $scope.data.displayBean = theEvent.data;
  });
}

can you try $scope.data.displayBean = theEvent.data;

Comments