Issue
We can get async pipe as variable with *ngIf
<button *ngIf="account$ | async as account" (click)="parseAccount(account)" type="button"></button>
But of course it won't work for boolean values, for example
<button *ngIf="loggedIn$ | async as loggedIn" (click)="checkAuth(loggedIn)" type="button"></button>
Because loggedIn$ | async
can emit false.
Is there any other built-in way to get async values as template variable without custom ngInit directives?
Solution
Just found an answer
<button *ngIf="{ val: loggedIn$ | async } as loggedIn" (click)="checkAuth(loggedIn.val)" type="button"></button>
Maybe a little bit hacky but works
Note that *ngIf
is used here not for visibility but as a way to get a template variable
Answered By - Dzmitry Vasilevsky
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.