I am trying to console.log data in my app.component file coming my service file. I am getting undefined.
Here is my code
service.ts
getBillingCycles() {
return this.http.get('../../assets/download_1.json');
};
app.component.ts
export class AppComponent implements OnInit{
title = 'ngMTN';
billing: any;
constructor(private http: HttpClient, private BillingCyclesService: BillingCyclesServiceService) { }
ngOnInit() {
this.getBillingCycles();
}
getBillingCycles() {
this.BillingCyclesService.getBillingCycles()
.subscribe(data => this.billing = data);
console.log(this.billing);
}
}
You need to place the console log within the subscribe,
this.BillingCyclesService.getBillingCycles()
.subscribe((data) => {
this.billing = data;
console.log(this.billing);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With