last day (14 days later) » 

10:21 AM
1
Q: Angular Promise - $q.all not returning result and calling Post method several times not working

ZakiAm trying to call a Post method and then depending on the result I am going to call same Post method multiple times and return the result, using $q.all. My Post method is : getData: function (params, callback) { $http.post('service/myService', params) .succ...

 
Add return to getData $http
 
@Kindzoku what do you mean?
 
btw, why do you need $q.all?
 
so that it resolves all promises before hitting the callback function...
 
But there is no need to use all. Actually, you call checkForPaging next time only when your previous call is done (it's in callback).
 
10:21 AM
I am new to angular & promises...so went for $q.all :) can you please update your answer with how I should chain the whole thing. I tried dfsq's answer but it calls it only once and it doesn't go inside the return service.getData(criteria, data) function
 
Zaki, you're doing it a bit wrong.
You really need the new approach. There is no more .error() and .success() methods on $http
New approach is:
$http.post('URL', function(result){}, function(error){});
I'll try to rewrite your solution in a modern way, brb in 5 mins
 
cool thanks
 
Why do you need promise at all?
How will you use data?
To populate list?
 
10:51 AM
I've posted an answer. Feel free to ask questions :)
 
yes am populating a select
cool thanks will check it :)
 
Wait )
If you populating a select, you don't need promise :)
I'll update solution for both ways.
Updated. :) Well, don't forget to mark my answer as solution, if it'll help ;) Have a nice day.
 

last day (14 days later) »