I am building a fairly complex service with lots of models and functions. Part of the service looks like this:
// Sports model
var sports = {
list: function () {
// Create our deferred promise
var deferred = $q.defer();
// Get our categories
moltin.categories.list(0, 0).then(function (response) {
// Create our list
list = [];
// Loop 6 times
for (var i = 0; i < 6; i++) {
// Get our column index
var colIndex = i + 1;
// Return our spliced array
list.push(response.splice(0, 7));
}
// Resolve our list
deferred.resolve(list);
});
// Return our promise
return deferred.promise;
}()
};
which is then assigned to the service and returned like this:
var service = {
sports: sports
}
return service;
Now, as you can see I am calling an API (moltin is another service which returns a promise). In my controller I want to do this:
self.list = service.sports.list
Because the method is self executing I expected to actually have a list of categories, but instead I just get the promise. Does anyone know how I can get the list without having to do this:
service.sports.list().then(function (response) {
self.list = response;
});