I need to get some information (a schema) from the server before I set up a bunch of services that depend on that information.
My server provides a schema that defines v
You get a promise because your service function immediately evaluates its body when you call it (as functions do). Normally, a service should return an object so that the consumer (another service, controller, whatever) may then call the functions on that object when it needs to.
services.factory('schema', function($q, $http) {
return {
get: function() {
var deferred = $q.defer();
$http.get('schema/').then(function(response) {
schema = // some function of response.data
deferred.resolve(schema);
}, function() {
deferred.reject('There was a problem fetching the schema');
});
return deferred.promise;
}
}
});