1👍
✅
just move your data
inside your observable. You’re working with asynchronous operation.
ngOnInit() {
this.reportService.getSR('Month',lastMonth,today)
.subscribe(response => {
this.data = {
labels: response.map(item => { return item.month_name });
datasets: [
{
label: 'First Dataset',
data: this.srCount,
fill: false,
borderColor: '#4bc0c0'
}
]
}
});
}
0👍
If all you need is to not “nest” the month name array you can use the array.push.apply(array, array2) approach (see link below).
So for your array:
this.monthName.push.apply(this.monthName, monthName);
Source:stackexchange.com