Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I list Observable array with async pipe using @for in Angular 18?

I try to upgrade to Angular 18, I encountered a problem about for-loop from *ngFor to @for in template.

<!-- It works -->
<div *ngFor="let item of items$ | async">
    {{ item.name }}
</div>

I don’t have any idea to list Observable items$ using @for in template

@for (item of items$; track item.id) {
    {{ item.name }}
}

Could anyone give me advice?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Wrap your observable & the AsyncPipe with parenthesis.

@for (item of (items$ | async); track item.id) {
    {{ item.name }}
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading