TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
balaji balaji
NA
14
1.1k
Angularjs Chaining Promises and $q
Apr 29 2019 5:41 AM
while executing the code alert("promiseC done") is displaying first and then alert("promiseC"); is displaying last because of this the data was not displaying properly from function Displaydata(); from below code.
App.controller(
"Ctrl"
,
function
($scope, $http, $location, $window, $sce, $q) {
var
promiseA = getMA(Id).then(
function
() {
alert(
"GOT MA data from API call"
);
// doing some stuff with MA data ...
}
var
promiseB = getMB(Id).then(
function
() {
alert(
"GOT MB data from API call"
);
// doing some stuff with MBdata ...
}
var
promiseC = getMC(Id).then(
function
() {
alert(
"GOT MC data from API call"
);
// doing some stuff with MC data ...
getotherdata(MC.Id).then(
function
() {
. .
}
..
alert(
"promiseC"
);
}
var
promiseB = promiseA.then(
function
(result) {
alert(
"promiseA done"
);
});
var
promiseC = promiseB.then(
function
(result) {
alert(
" promiseB done"
);
});
var
promiseD = promiseC.then(
function
(result) {
alert(
"promiseC done"
); Displaydata();
});
}
How can i make to work properly so that alert("promiseC") will display first and then alert("promiseC done").
Also tried in below way but same issue as above in chain promises.
var
promiseA =
function
(){
var
deferedA = $q.defer();
deferedA.resolve();
return
deferedA.promise;
}
var
promiseB =
function
(){
var
deferedB = $q.defer();
deferedB.resolve();
return
deferedB.promise;
}
var
promiseC =
function
(){
var
deferedC = $q.defer();
alert(
"promise c"
);
deferedC.resolve();
return
deferedC.promise;
}
$q.all([promiseA, promiseB, promiseC]).then(
function
() {
alert(
"all done"
); Displaydata();
})
Reply
Answers (
3
)
Integrating Angular JS into jquery based E-commerce site
Angular 7 querystring param getting 'undefind'