lundi 7 mars 2016

How to create a service that both returns a promise and exposes a set of functions?

Let's suppose I have a simple service:

angular.module('myModule')
    .factory('myService', ['$http', function($http) {
        return $http.get('/something');
    }]);

Now whenever I inject the service into a controller, the router waits for the promise to resolve before changing the route, which is exactly what I want.

However, there doesn't seem to then be a way to return other data from the service. What if the service needs to also provide some methods? How can I do this while still maintaining the dependency behavior described above?

Aucun commentaire:

Enregistrer un commentaire