I have an Angular Universal app that calls an ASP.Net Web API service.
I have put Console writes on the Angular call to the web service (which was initiated from either a component's constructor or ngOnInit, I tried both) and the subscriber function in Typescript, as well as on the Web API method.
When running the app, I notice that the Angular Universal app does not wait for the Web API's result.
The last console write message that I get is from the Web API, not from the function in the subscriber call.
How can I force the Angular Universal app to wait for the result before finishing the render?
As long as you are using the Angular HttpClient, the server-side-render should wait for it to finish before serving your response.
If this doesn't work for you, try subscribing to the call using the | async pipe in your template code.
For example:
export class MyComponent {
public response$ = this.httpClient.get<string>('https://my.api');
constructor(private httpClient: HttpClient){}
}
<span> {{ response$ | async }} </span>