Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ngIf in angular 17 with async pipe as a variable

Tags:

angular

I have this in Angular 16

<div *ngIf="post$ | async as post">
  <h1>{{ post.attributes.title }}</h1>
</div>

Type of post$ is Observable<ContentFile<BlogPost | Record<string, never>>>

I want to rewrite this with the new built-in syntax for control flow.

@if(post$|async as post) {

}

as post part results in

Parser Error: Unexpected token 'as' at column 13 in [post$|async as post] in ...

How to get around this?

like image 815
naveen Avatar asked Aug 30 '25 15:08

naveen


1 Answers

You're missing the semi colon :

@if(post$ | async; as post) {

}
like image 91
Matthieu Riegler Avatar answered Sep 03 '25 00:09

Matthieu Riegler