在Angular 2 HTML元素中订阅observable

编程入门 行业动态 更新时间:2024-10-25 12:28:49
本文介绍了在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

本文发布于:2023-11-22 23:34:14,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   Angular   HTML   observable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!