I am trying to extract my daily hours from my app using an Observable and process this data as an array,but right now I get this data in JSON format.
calculation.service.ts:
items: { [key: string]: IItem } = {};
private update = new Subject<void>();
getDailyHours(): Observable<{ [key: string]: string }> {
return this.update
.map(() =>
_.chain(this.items)
.values()
.groupBy("date") //date is of type string
.mapValues(items => this.timeService.format(_.sumBy(items, "spent")))
.value()
)
.distinctUntilChanged(_.isEqual);
}
overview.component.ts
dailyHours: { [key: string]: string } = {};
ngOnInit(){
this.calculationService.getDailyHours().subscribe(s => {
this.dailyHours = s;
console.log(this.dailyHours);
});
}
getHours(date: string) {
const sum = this.dailyHours[date];
return sum === "0m" ? "" : sum;
}
dailyHours gets printed in console like this :
{08.04.2018: "0m", 09.04.2018: "0m", 10.04.2018: "0m", 11.04.2018: "0m", 12.04.2018: "0m", …}
This makes it difficult to parse my data when given dynamic data.(fx: if i go 1 week back my json will have different key values "01.04.2018", ..."07.04.2018")
How can I modify my observable to output an array instead of JSON ?