I am experiencing the same issue as posted in a recent topic - 30702965 Accessing objects returned from a factory. In fact I have followed the advice in that response but still do not get any results in the view. As in that previous post I have created a factory:
myapp.factory("eventsService", function($http) {
var events = [];
return {
getEvents: function() {
return $http.get('data/events.php').then(function(response) {
events = response;
// console.log(response);
return events;
});
}};
});
This returns the promise which is seen in the console.log.
I coded the controller as per the advice in the response as follows:
myapp.controller('eventsController', function($scope, eventsService) {
$scope.events = [];
eventsService.getEvents().then(function(data){
$scope.events = data;
console.log(data);
});
});
Again, the console.log shows that I have got the object:
object {data: Array[2], status: 200, config: Object, statusText: "OK"}
All good so far, but I still don't get anything in the view:
<ion-content ng-controller="eventsController">
<ion-item ng-repeat="event in events">{{ event.title }} </ion-item>
</ion-content>
I'm lost as how to display the events. What am I missing?
Oh, by the way although this is a php backend going to a mysql database it is working. In fact if I don't use a service and code the http get directly into the controller it all works fine and I see the results as expected.
Please help this is driving me nuts!!