Giacomo Masseroni Chiaro Giacomo Masseroni Chiaro - 1 year ago 62
AngularJS Question

angularjs: chain promises returns a promise instead of an object

I have a chain promises and I want to return an object instead of a promise. Instead I get a promise.
This is the function:

self.get = function(id) {
var parameters = [id];
var orders = {}
return DBA.queryAgent("SELECT * FROM Orders WHERE " + column_id + " = ?", parameters).then(function(result) {
return DBA.getById(result);
}).then(function(result) {
order = result;
return self.getProdutcs(id);
}).then(function(result) {
order.Products = result;
return order;

I expect that


returns an object, I get a promise. Where am I wrong?

Thank you

Answer Source

From the angular docs$q

calling the then method of a promise returns a new derived promise,

It is the way angular is written. Hence, you have to access it like this.

 service.get.then(function(result) {
    // whatever
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download