When you write
promiseGetWorkTypes($q, $http, $scope).then(promiseGetRecentActivities($q, $http, $scope));
promiseGetActivites is invoked during the calculation of this string. You should be able to wrap the promiseGetActivities call in another function to defer the call until the first promise decides that the calls are executed sequentially:
promiseGetWorkTypes($q, $http, $scope).then(function() { promiseGetRecentActivities($q, $http, $scope); });
The reason has nothing to do with what happens inside then , but because of the Javascript syntax. Following:
myFunc1(myFunc2());
passes myFunc1 the result of calling myFunc2() , not a link to the myFunc2 function. Thus, logically myFunc2 should execute before myFunc1 . If you wrote
myFunc1(myFunc2);
then myFunc1 will get a link to myFunc2 , and therefore myFunc1 will be executed before myFunc2 (and in fact, myFunc2 will be executed only if somewhere inside myFunc1 there is code that calls it).
Defining an inline / function does not anonymously change this behavior. To pass the result of an anonymous function to another function, you can do the following
myFunc1((function() { return 'something'; })());
which will first evaluate the anonymous function, since its return value of 'something' will be passed to myFunc1 . To pass a link to an anonymous function, you can do the following:
myFunc1(function() { return 'something'; });
and then there will be myFunc1 , whether it will ever call the function passed to it.
Returning it to your question, your code:
promiseGetWorkTypes($q, $http, $scope).then(promiseGetRecentActivities($q, $http, $scope));
passes the result from promiseGetRecentActivities($q, $http, $scope) to then , so it should be run before then starts and therefore, of course, did not wait for the promise to be promiseGetWorkTypes from promiseGetWorkTypes . What it seems to you is to pass it a function that, when called, starts promiseGetRecentActivities($q, $http, $scope) , which is what
promiseGetWorkTypes($q, $http, $scope).then(function() { promiseGetRecentActivities($q, $http, $scope); });
does.
As a side note, it seems a bit unusual / complicated to pass $q , $http , etc. for various functions, but I think that maybe this is beyond the scope of this question to go through alternatives.