问题描述:

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

service.get(1)

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

Thank you

网友答案:

From the angular docs https://docs.angularjs.org/api/ng/service/$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
  });
网友答案:

You can access the value by doing the following:

  service.get.then(function(result) {
    console.log(result);   
  });
相关阅读:
Top