Subscribe to an HTML Element Observable in Angular 2

I have an observable creature Userswith a property isLoading, so this gives the expected result:

{{ (user$ | async).isLoading }}

I would like to be able to use this property isLoadingin an HTML attribute, for example:

<button md-raised-button type="submit" [disabled]="user$.isLoading">Login</button>

but no syntax that I use seems to do the trick. How do you subscribe to observable like in HTML attribute?

+4
source share
2 answers

You can use async pipe in the html tag, as in the example below, just don't forget the safe statement:

<button md-raised-button type="submit" [disabled]="(user$ | async)?.isLoading">Login</button>
+2
source

, , Angular 4, - *ngIf. - :

<div *ngIf="user$ | async; let user">

{{user.isLoading}}    

<button md-raised-button type="submit" [disabled]="user.isLoading">Login</button>

</div>

*ngIf async let. .

, Angular 4. Angular2 4 - .

, .

+1

Source: https://habr.com/ru/post/1675828/


All Articles