Skip to content
Advertisement

async and await in angular api response

I am trying to do task step by step.

I have a for loop in a method:

JavaScript

for each step must do() task.

JavaScript

I want to wait to get response and after response coming go to next i

But not work console.log print:

JavaScript

Note time to receive response from api is not fix.

Any help?

Advertisement

Answer

You can return a Promise and use resolve() in response part of your ajax. Like:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement