Currently, I am in the process of retrieving data from a server and displaying it on an Ionic page. I have successfully fetched the data without any issues and verified it in the console. However, how do I proceed once the server returns the data to me?
The function responsible for loading the article is located within a provider:
public LoadArticle(article_id:any){
let headers = new Headers();
let postData:any;
postData = {
task: 'GetArticle',
article_id: article_id
}
headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
return this.http.post(this.apiUrl, JSON.stringify(postData),{ headers: headers });
}
To display the article, I call this function on the desired page:
constructor(
public navCtrl: NavController,
public controller: WebservicesProvider
) {
}
this.controller.LoadArticle(1).subscribe(
data => {
let retorno: any;
retorno = data;
console.log(JSON.parse(retorno._body));
// this.navCtrl.setRoot(AbasPage);
// this.article_array = retorno._body.dados;
this.articlearray.id = retorno._body.dados.id;
this.articleLoaded = true;
},
error => {
console.log(error)
this.controller.endLoading();
},
() => {
this.controller.endLoading();
}
);
When attempting to reference {{articlearray.id}} in the HTML file of the page, I encounter the following error:
Cannot read property 'id' of undefined
I'm puzzled as to what could be causing this issue. Where might I be going wrong in my implementation?