This condition should be handled with nested ngIf
directives:
<ng-container *ngIf="language$ | async as language">
<div *ngIf="user$ | async as user">
<b>{{language}}</b> and <b>{{user}}</b>
</div>
<ng-container>
The downside is that HTTP requests will be performed in series.
In order to perform them concurrently and still have language
and user
variables, more nesting is required:
<ng-container *ngIf="{ language: language$ | async, user: user$ | async } as userLanguage">
<ng-container *ngIf="userLanguage.language as language">
<ng-container *ngIf="userLanguage.user as user">
<div><b>{{language}}</b> and <b>{{user}}</b></div>
</ng-container>
</ng-container>
</ng-container>
More efficient way way to do this is to move logic from template to component class at this point and create a single observable, e.g. with withLatestFrom
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…