Apologies if this is near a duplicate question, however all other question are either un answered or not quite as close to this issue.
I'm in Ionic 3 and I am using this code to get JSON from a feed:
getMenu(){
let path = 'URL';
let encodedPath = encodeURI(path);
this.http.get(encodedPath)
.map(res => res.json())
.subscribe(data => {
let responseData = data;
if(responseData.status=='success'){
var JSONObject = responseData.data;
this.menuItems = JSONObject;
console.log(JSONObject);
}
},
err => {
console.log('error ' + err);
});
}
I call that function in both ionViewDidLoad and the constructor. And then in my page I'm trying to access the data in that feed on the page with:
{{ menuItems.length }} etc etc
I think i'm aware of the fact that the data will probably come in after the page has loaded as the error i'm getting is
Cannot read property 'length' of undefined
The console does show me the correct data that is pulled in, good. But as I have read, this will happen asynchronously. All the tutorials I have read say it just works, well it certainly doesn't!! Thanks in advance...