Service not working on the simulator


#1

Hi everybody!

I’m kind of new with AngularJS. I have a service that works fine on the browser but when I run the app on the simulator it doesn’t work. I’m pretty sure it’s something really simple…

Here is the service:

myApp.service('eventsService',function($http,$ionicLoading) {
    var events;

    return {
        getEvents:function(){
            $ionicLoading.show({templateUrl: 'templates/loading.html'});
            return $http.get(apiurl + 'events').then(function(resp) {
                events = resp.data.events;
                $ionicLoading.hide();
                return events;
            }, function(err) {
                $ionicLoading.hide();
                return events;
            });
        }
   }
});

Here is the controller:

myApp.controller('eventsCtrl', function($scope, eventsService)  {

	eventsService.getEvents().then(function(events) {
        $scope.events = events;
        $scope.past_events = eventsService.getPastEvents();
        $scope.future_events = eventsService.getFutureEvents();
    });

});

If on the controller instead of calling the service I do the request it works fine on the browser and on the simulator:

$http.get(apiurl + 'events').then(function(resp) {
	$scope.tracks = resp.data.events;
	$ionicLoading.hide();
}, function(err) {
	$ionicLoading.hide();
	console.error('ERR', err);
});

Thanks in advance!