multiple `.then()`s on single angularjs promise -- all use _original_ data

Solution 1:

Turning my comment into an answer since it seems to clear up the issue:

With your pattern, the two .then() calls on the same promise are going to get called one after another when the promise is resolved. The second .then() has only to do with the original promise and nothing to do with what happens on the first .then().

These are not chained so the second .then() has no dependency upon what is returned from the first .then() and both will be passed the same data. They are just multiple watchers of the same promise kind of like two event handlers listening for the same event.

The two .then() handlers on the same promise will be called in the order they were attached to the promise and will both be passed the same data.

See these two answers:

Is there a difference between promise.then.then vs promise.then; promise.then

Understanding javascript promises; stacks and chaining

for more info on chaining p.then(...).then(...) vs. branching p.then(...); p.then(...) with promises.

Solution 2:

You need parallel execution: $q.all()

$q.all(
    function1,
    function2,
    function3
).then(function(responses) {
    console.log(responses);
});