7

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" 
1
  • What i used to d o if thats an option for you is to create a custom component where the list is given as an input parameter. That always works and is way cleaner to read in my opinion Commented May 29, 2019 at 12:25

2 Answers 2

13

try this :

<li *ngFor="let image of (album$ | async)?.images">
 <h1>{{ image }}</h1>
</li>
Sign up to request clarification or add additional context in comments.

Comments

3

This should work for you with safe navigation operator

<li *ngFor="let image of (album$ | async)?.images ">
  <h1>  {{ image }} </h1>
</li>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.