I've developed an Angular service that serves as a middleman for fetching data from a database. Here's the code:
export class WebService {
constructor(private http: Http, private datePipe: DatePipe) {
this.getStatsbyDate(this.datePipe.transform(new Date(), 'dd-MM-yyyy'));
}
statsModel = {
date: this.datePipe.transform(new Date(), 'dd-MM-yyyy'),
answeringMachine:0,
hangUp: 0,
conversations: 0
};
getStatsbyDate(date) {
this.http.get(this.BASE_URL + '/stats/' + date)
.subscribe(
res => {
this.btnsOnResponse = true;
this.statsModel = res.json();
// console.log(this.statsModel);
},
err => {
console.log("Couldn't fetch data")
}
);
}
In one of my Angular components, I'm attempting to access the retrieved data like so
export class FusionChartsComponent implements OnInit {
constructor(private webService: WebService) {}
ngOnInit() {
console.log(this.webService.statsModel.answeringMachine);
}
}
I'm perplexed by this behavior and seeking advice on resolving it.