0

I have two objects layers$ and arrayByLayerId$ that I get asynchronously in my component, the structure of the objects is as following :

interface Layer {
   id: number;
   ...
}
{
   1: []
   2: []
   ...
}

Is there a way to iterate over arrayByLayerId$ arrays with the async pipe in the template like something below (the syntax is not correct it's just to illustrate what I try to achieve) :

<div *ngFor="let layer of layers$ | async"
     [attr.id]="layer.id">

    <my-component *ngFor="let array of arrayByLayerId$[layer.id] | async" [array]="array"><my-component/>
</div>

Thanks !

3
  • 1
    doesn't work mean nothing. Are you sure that arrayByLayerId$[layer.id] | async is actually working? Commented Feb 18, 2020 at 8:27
  • Needs to be put though async pipe before member access [layer.id] Commented Feb 18, 2020 at 8:27
  • I guess you could use eg. foo$ = combineLatest([layers$, arrayByLayerId$]) and then foo$ | async Commented Feb 18, 2020 at 8:35

1 Answer 1

2

arrayByLayerId$ does not have a value yet before you access its "layer.id" property. It should be like this :

 <my-component *ngFor="let array of (arrayByLayerId$ | async)[layer.id]" [array]="array"><my-component/>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.