我的组件模板中有以下内容:
< div * ngIf =“user $| async as user> …< / div>
在上面的div中,我想使用异步管道只订阅一次另一个observable,并在整个模板中像上面的用户一样使用它.因此,例如,这样的事情是可能的:
<ng-template *ngIf="language$| async as language> <div *ngIf=" user$| async as user> <p>All template code that would use both {{user}} and {{language}} would go in between</p> </div> </ng-template>
或者甚至可以在一个声明中合并?
您可以将object用作变量:
<div *ngIf="{ language: language$| async,user: user$| async } as userLanguage"> <b>{{userLanguage.language}}</b> and <b>{{userLanguage.user}}</b> </div>
也可以看看