I have following Database structure :
I am a bit confused about how to get the value of an object from April and May key. While using *ngFor for iterating over the object. I have All keys as objects . l tried to use keyvalue
but doesn't working .
Full Code :
orderhistory: AngularFireList<any>;
keyArray: any[]; // to use with *ngFor
ngOnInit() {
this.orderhistory = this.af.list("/orderhistory")
this.orderhistory.snapshotChanges()
.pipe(
map(changes =>
changes.map(c => ({ $key: c.payload.key, ...c.payload.val() }))
), tap(val => this.keyArray = []), map(data => {
data.forEach((row, dataObj) => {
Object.keys(row).forEach((r, objIndex) => {
if (r === '$key') {
this.keyArray.push({ row: row['$key'], 'value': [] });
} else {
this.keyArray[dataObj]['value].push({ 'subRowKey': r, 'subRowValue': row[r] })
}
return row;
})
return row;
})
onsole.log(this.keyArray)
return data;
})
).subscribe((data: any) => {
console.log(data)
});
}
Html
<tbody *ngFor="let row of keyArray; let i = index">
<tr role="row" *ngFor = "let subRow of row.value |keyvalue; ">
{{subRow.subRowValue|json}}
</tr>
</tbody>
Output
As you see above , my data now become under subRowValue
. So how can i avoid or access to key for get data there ? is possible to use |keyvalue
?
{{subRow.subRowValue.value | json}}
in the template. Withkeyvalue
pipe you need specifykey
andvalue
to retrieve them. - Michael D*ngFor
s. I've posted an answer. Please see if it works for you. - Michael D