Wulf Wulf - 1 year ago 78
Javascript Question

AngularJS Why use $q.all() on one promise?

I'm familiarizing myself with a codebase, and I'm seeing this everywhere:


This does not make sense to me -- I've read the documentation, and I don't know why the following is not used instead, since it's already one promise...


Is there something I'm missing? What's the advantage of the former over the latter?

Answer Source

Yes, this is a bit weird, but there is a difference: responseFunc will be called with an array of the result instead of the result itself.

This probably should better be written as either

promise.then(res => responseFunc([res]))


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download