I want to iterate over key value pairs from an object and display two items per row. I looked at other examples like this one Example but I couldn't figure out how to add keyvalue to this.
Here is my code:
<div *ngFor="let item of book.bookData.privateData | keyvalue; index as i; let even = even">
<div fxFlex="100" fxLayout="row" *ngIf="even">
<div fxFlex="50" fxLayout="column">
Key: <b>{{book.bookData.privateData[i].key}}</b> and Value: <b>{{book.bookData.privateData[i].value}}</b>
</div>
<div fxFlex="50" fxLayout="column">
Key: <b>{{book.bookData.privateData[i+1].key}}</b> and Value: <b>{{book.bookData.privateData[i+1].value}}</b>
</div>
</div>
</div>
This does not work since there is no key
and value
attribute on the privateData
object, the attributes are assigned to item
.
Thanks in advance for any help!
EDIT:
The following is a working example of what I'm trying to achieve, but it's clearly not an efficient way:
<div *ngFor="let item of bookState.bookData.privateData | keyvalue; index as i; let even = even">
<div fxFlex="100" fxLayout="row" *ngIf="even">
<div fxFlex="50">
<div *ngFor="let deeperItem1 of bookState.bookData.privateData | keyvalue; index as i2">
<div *ngIf="i2 === i">
<b>INDEX {{i2}} and {{i}} </b>Key: <b>{{deeperItem1.key}}</b> and Value: <b>{{deeperItem1.value}}</b>
</div>
</div>
</div>
<div fxFlex="50">
<div *ngFor="let deeperItem2 of bookState.bookData.privateData | keyvalue; index as i3">
<div *ngIf="(i3-1) === i">
<b>INDEX {{i3}} and {{i}} </b>Key: <b>{{deeperItem2.key}}</b> and Value: <b>{{deeperItem2.value}}</b>
</div>
</div>
</div>
</div>
</div>
EDIT2:
To specify the question: The problem is not that the keyvalue pipe is not working, the problem is how to efficiently add indexes to these to display x-amount (in my case 2) of items per row. Sorry for any misunderstanding!