0

In my application I am using AngularJS and nodeJS for rest api and its working fine. But when I try to call api using for loop its having some problems. Actually only last set of Parameters are passing to the api.

It means if I pass different parameters using loop 3 times then only last set of parameters passing to the api 3 times. First and Second are not send to api. Can anybody have any Idea??

Here is a sample code I use in Angularjs Factory.

var firstTimeData = {
                        "firstid": serializedJsonData.firstid,
                        "secondid": serializedJsonData.secondid,
                        "otherid": serializedJsonData.otherid

                    }
                    for (var i = 0; i < data[0].length; i++) {
                        for (var j = 0; j <= 2; j++) {
                            firstTimeData.dshdetailid = data[i][j].dshdetailid;
                            if ((data[i][j].defaultTitle).trim() == 'Scorecard Graph') {
                                BlankApi.getData(firstTimeData, 'slide' + j, 'periodname', 'amount');
                            }
                        }
                    }
2

1 Answer 1

0

To fix this issue you have to make asynchronous calls in loop,

Here in this code for loop get continuously executed without waiting for each api call to get finished.

Refer this post to get idea about how to use asynchronous calls in loop

Sign up to request clarification or add additional context in comments.

2 Comments

I tried that but still that sending the same parameter again and again.
check whether you are getting different parameters in each iteration through loop?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.