Skip to content
Advertisement

wait for asynchronous functions to finish in Angular

So I was working on a new component in Angular and in the ngOninit I have the following asynchronous functions below…

This.getUserProfile needs to be finished before I can call this.getPrivateGroup() and this.getPrivateGroup() needs to be finished before I can call this.loadGroupPosts(). I know I could write these functions inside the callback of the asynchronous requests, but I was wondering if there is a way to keep it in ngOnInit to keep it cleaner?

Anyone has an idea?

JavaScript

Advertisement

Answer

You can use basic promises with async/await.

JavaScript

}

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