Ionic 3.
I try to use auth-servise in file home.ts:
import { Component } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
import { AuthServiceProvider } from ‘…/…/providers/auth-service/auth-service’;
import { WelcomePage } from ‘…/…/pages/welcome/welcome’;
@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {
public userDetails : any;
public responseData: any;
public dataSet: any;
userPostData = {“user_id”:"",“token”:""};
constructor(public navCtrl: NavController, public authService: AuthServiceProvider) {
const data = JSON.parse(localStorage.getItem('userData'));
this.userDetails = data.userData;
console.log(this.userDetails);
this.userPostData.user_id = this.userDetails.user_id;
this.userPostData.token = this.userDetails.token;
this.getData();
}
getData(){
this.authService.postData(this.userPostData,'bodygraph').then((result) => {
this.responseData = result;
if(this.responseData.bodygraphData){
this.dataSet = this.responseData.bodygraphData;
console.log(this.dataSet);
}
else{
console.log("No access");
}
}, (err) => {
// Error log
});
}
}
I created PHP API.
And I got data.
But I have error in file home.html:
Runtime Error
Cannot read property ‘age’ of undefined
I think that the file home.html opens earlier than I get the data.
I see it in console log:

Help me, please.