我的组件模板中有以下内容:
< div * ngIf =“user $| async as user> …< / div>@H_301_2@
在上面的div中,我想使用异步管道只订阅一次另一个observable,并在整个模板中像上面的用户一样使用它.因此,例如,这样的事情是可能的:@H_301_2@
<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>
或者甚至可以在一个声明中合并?@H_301_2@
您可以将object用作变量:
原文链接:https://www.f2er.com/angularjs/143743.html<div *ngIf="{ language: language$| async,user: user$| async } as userLanguage"> <b>{{userLanguage.language}}</b> and <b>{{userLanguage.user}}</b> </div>
Plunker Example@H_301_2@
也可以看看@H_301_2@
> How to declare a variable in a template in Angular2@H_301_2@