在Angular 2 HTML元素中订阅observable [英] Subscribing to an observable in an Angular 2 HTML element
本文介绍了在Angular 2 HTML元素中订阅observable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个可观察的产生 Users
的 isLoading
属性,这样可以得到预期的结果: / p>
I have an observable producing Users
that have an isLoading
property, such that this yields the expected result:
{{ (user$ | async).isLoading }}
我希望能够在HTML属性中使用 isLoading
属性,如下所示:
I would like to be able to use this isLoading
property in an HTML attribute, like this:
<button md-raised-button type="submit" [disabled]="user$.isLoading">Login</button>
但我没有使用任何语法似乎可以做到这一点。如何在HTML属性中订阅这样的观察值?
but no syntax I use seems to do the trick. How do you subscribe to an observable like this in an HTML attribute?
推荐答案
您可以在html标记中使用异步管道下面,只是不要忘记安全的操作符:
You can use async pipe in html tag like in example below, just don't forget safe operator:
<button md-raised-button type="submit" [disabled]="(user$ | async)?.isLoading">Login</button>
这篇关于在Angular 2 HTML元素中订阅observable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文