I have implemented a if statement like this
if (this.service.check() ) {
return true;
}
else {
}
this if condition waits for a response from the backend. But before the observable gets executed it's going into the else statement and finishing the condition without checking the if condition at start.
this is my observable method to get the data from backend
public check(){
this.getActorRole().subscribe(
(resp => {
if (resp == true){
return true
}
}),
(error => {
console.log(error);
})
);
}
}
So how make the condition waits until it gets the response from the backend
You can't wait for an
Observable
orPromise
to complete. You can only subscribe to it to get notified when it completes or emits an event.then you can do
but if the caller of this code also depends on the return value you again need to
and then do the
subscribe()
where you call this code