I am pulling data from an API for recipes, I already have a list of recipes which works fine, however I am now calling for a single recipes details (1 object). My console log below is what the JSON looks like. Whatever I do I cannot get to display on the front end, please help where you can.
TypeScript
details: any;
loadDetails() {
if (this.details) {
return Promise.resolve(this.details);
}
return new Promise(resolve => {
this.http.get('http://api.yummly.com/v1/api/recipe/Crustless-Ham-Savory-Bake-2005439?_app_id=//////&_app_key=/////')
.map(res => res.json())
.subscribe(data => {
console.log(data);
this.details = data;
resolve(this.details);
});
});
}
HTML
<ion-content>
<ion-list>
<ion-item>
<h1>{{details.id}}</h1>
</ion-item>
</ion-list>
</ion-content>
Pagename.ts
@Component({
selector: 'page-details',
templateUrl: 'details.html',
providers: [ApiAuthentication]
})
export class DetailsPage {
public api: any;
constructor(public navCtrl: NavController, public navParams: NavParams, public apiAuthentication: ApiAuthentication) {
this.loadRecipes();
}
ionViewDidLoad() {
console.log('ionViewDidLoad DetailsPage');
}
loadRecipes(){
this.apiAuthentication.loadDetails()
.then(data => {
this.api = data;
});
}
}

details.idbeforedetailsis actually defined (it is NOT assigned immediately since it is the result of an async cold). Try{{details?.id}}in your template.<h1>{{details?.id}}</h1>. That's because the promise is not yet resolved when trying to print the id.