0

how i can make storyboard.getAdressTimeLine Synchronously, i want storyboard.drawTimeLine executes untill storyboard.getAdressTimeLine is finished

for (var i = 0; i < response.data.length; i++) {
var obj=response.data[i];
var date = obj.fixtime.substring(0, 11);
storyboard.getAdressTimeLine(obj.latitude,obj.longitude);
storyboard.drawTimeLine(date + "00:00:00.000+0000", obj.fixtime, "red",0,storyboard.lastAdressTime);
items.push(item);

}

  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Arg0n Jun 05 '17 at 13:16

1 Answers1

0

Use promises over here this angularjs documentation will help you https://docs.angularjs.org/api/ng/service/$q

If you use promise your function will look like

storyboard.getAdressTimeLine(obj.latitude,obj.longitude).then(function(){
 storyboard.drawTimeLine(date + "00:00:00.000+0000", obj.fixtime, "red",0,storyboard.lastAdressTime);
})
Vikash Kumar
  • 1,712
  • 1
  • 11
  • 17
  • thanks for your ansswer..i have already this in my function.. but it doesnt work –  Jun 05 '17 at 13:21