I am having trouble displaying image from server in ionic mobile app.
I am getting response from api in json format. Each object is having 2 urls, one is normal url and other is image url
The issue is that the image-url is shown as undefined when I try to print it using console.log, but it’s actually present in the object !!
Normal url is shown correctly in console.log
Problem is only with image-url…
Following is my class
export class Source{
id:any;
name:string;
}
export class News{
source:Source;
author:string;
title:string;
description:string;
url:string;
urlToImg:string;
publishedAt:Date;
content:string
}
export class NewsRsponse{
status:string;
totalResults:number;
articles:News[];
}
Display code
ngOnInit() {
this.newsService.getAllNews().subscribe((data)=>{
this.newsResponse = JSON.parse(JSON.stringify(data));
console.log('news : ',this.newsResponse);
this.listOfNews = this.newsResponse.articles;
for (const news of this.listOfNews) {
console.log(news);
console.log(news.urlToImg);
}
})
}