In Angular 11, why does the code following a service call keep on executing even when the service call has not finished?
In Ang11, in a xComponent.ts, I have the following structure:
Why does Line 3 start executing even when the service call has not yet finished fetching & returning the data?
Is this something do with Async calls? How to stop it? With Promise? Sorry, I come from a Java world and learning Angular, and all this is a bit overwhelming for me.
Line 1: <code>
Line 2: UserDetails ud=this.getUserDetails(userID)
Line 3: <code to work with ud>
Line 99: getUserDetails(){
this.userService.getUserDetails(userID).subscribe((data: UserDetails) => {
userDetails:data;
});
return userDetails;
}