I am working on a component, where I need to call two APIs parallelly. And I want to call a method only when both the API calls are resolved.
ngOnInit() {
this.serviceOne.someApi().subscribe((res) => {
this.response1 = res;
});
this.serviceTwo.someApi().subscribe((res) => {
this.response2 = res;
});
}
I want to call a method only when this.response1
and this.response2
is getting populated.
Currently, I am wrapping the logic inside the method with an if statement
.
someMethod() {
if(this.response1 && this.response2) {
//logic
}
}
and putting someMethod()
inside subscribe()
of both the api calls.
What is the best way to achieve this?