嗨,我有一个可观察的 user$ 对象,拥有许多属性(如名称、标题、地址...)
component{
user$:Observerable<User>;
constructor(private userService:UserService){
this.user$ = this.userService.someMethodReturningObservable$()
}
}
有没有办法在HTML模板中使用async管道来订阅它并将其绑定到本地变量,就像这样:
是否可以使用async管道在html模板中订阅并将其绑定到本地变量?
<div #user="user$ | async">
<h3> {{user.name}}
</div>
我知道可以在构造函数中订阅它,然后在 OnLeave/OnDestroy 中取消订阅,但我只是好奇是否可以使用异步管道。
干杯
*ngFor="let u of (user = (user$ | async))"
,但似乎有些可疑。需要更实际的操作。 - Babar Hussain