I'm using the new Angular local variable assignment feature to reference the result of an async pipe in child elements under an ngIf
:
<nav *ngIf="dataService.count$ | async as count">
<div *ngIf="count > 1">
There's more than one! It's actually {{count}}.
</div>
</nav>
As you can see, I have an extra div
in the hierarchy just to grab the result of the async pipe and then do a comparison against it. I feel like I should be able to do this in a single expression but I can't find enough documentation about the new feature. I've tried a variety of approaches with parens, using | async; let count
instead, etc, but I can't figure out how to do both things in one line.
(A pointer to any documentation on local variable declaration syntax in ngIf
would be much appreciated too -- I had never heard of foo$ | async as foo
until I saw it here on SO.)