Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate over an array in an object with async pipe

I have an object literal album$ that I get asynchronously into my component

album$: Observable<Album> = this._selectedAlbumSandbox.selectedAlbum$;

The Album interface looks as follow and as you see it has an array of Image.

export interface Album {
  id: string;
  name: string;
  caption: string;
  images: Image[];
}

Now, how can I loop over the images array in my template using an async pipe? Something like the following

 *ngFor="let image of album$.images | async" 
like image 356
sjbuysse Avatar asked Nov 12 '17 13:11

sjbuysse


1 Answers

try this :

<li *ngFor="let image of (album$ | async)?.images">
 <h1>{{ image }}</h1>
</li>
like image 50
Fateh Mohamed Avatar answered Oct 06 '22 05:10

Fateh Mohamed