Been trying to combine two observables into one *ngIf
and show the user interface when both have emitted.
Take:
<div *ngIf="{ language: language$ | async, user: user$ | async } as userLanguage">
<b>{{userLanguage.language}}</b> and <b>{{userLanguage.user}}</b>
</div>
From: Putting two async subscriptions in one Angular *ngIf statement
This works as far as it compiles however in my case language$
and user$
would be from two HTTP requests and it seems user$
throws runtime errors like TypeError: _v.context.ngIf.user is undefined
.
Essentially what I really want is (this doesn't work):
<div *ngIf="language$ | async as language && user$ | async as user">
<b>{{language}}</b> and <b>{{user}}</b>
</div>
Is the best solution:
- Subscribe inside the component and write to variables
- To combine the two observables inside the component with say
withLatestFrom
- Add null checks
{{userLanguage?.user}}