sorry i cant show full code here, i came up with the following code snippet. I have a service and controller. In service, I added a 2 second timeout to my group service to test out spinner loading.
but somehow in controller, my code runs right away, without waiting for 2 seconds.
I did 3 break points, the order of execution i expected is : 2->1->3 but, it ended up with 2->3->1
Here is my service.
groupService.get = function() {
var deffered = $q.defer();
deffered.promise = $getMyDataStuffPromise.then(function (data) {
$timeout(function() {
deffered.resolve(); <- break point 1
}, 2000);
}, function (error) {
deffered.reject();
console.log('group error', error);
});
return deffered.promise; <- break point 2
};
controller:
$q.all([
PeopleSvc.get(),
GroupSvc.get()
]).then(function(data){
console.log('data returns, stop spinner'); <- break point 3
});
could you please let me know what was wrong with this code? thanks!