Search code examples
angularevent-binding

Angular async parameter in template statement


I'm currently having a hard time trying to figure out how to use async parameter in a template statement while doing event binding.

I've tried the following snippet:

<div (click)="goToProfile((user|async)?.id)"></div>

and it fails with

ng: Parser Error: Cannot have a pipe in an action expression at column 20 in [goToProfile((user|async)?.id)] in @2:19 ng: The pipe '' could not be found


Solution

  • you can do it like that

    <div *ngIf="user | async as u" (click)="goToProfile(u.id)"></div>