[英]Getting object in object from json api angular doesn't show
I want to get images from an api , but I don't know how to structure my code to access the exact object inside object.我想从 api 获取图像,但我不知道如何构造我的代码来访问 object 中的确切对象。
Api: http://api.tvmaze.com/shows api: http : //api.tvmaze.com/shows
My interface look like this:我的界面是这样的:
export interface MovieModel {
id: number;
name: string;
summary: string;
images: Images[];
type: string;
status: string;
url: string;
genres: { [key: string]: Genres};
}
export interface Images{
medium: string;
original: string;
}
export interface Genres{
g: string[];
}
And I call the api here:我在这里调用 api:
this.http.get(this.apiKey).subscribe((data: MovieModel[]) =>{
console.log(data);
this.Movies = data;
And in my HTML:在我的 HTML 中:
<ion-card-title>
{{movie.name}}
</ion-card-title>
<ion-img src="{{movie.images}}"></ion-img>
Any suggestions for getting images?获取图像的任何建议? thanks
谢谢
I've found the solution.我找到了解决方案。 I changed interface to this:
我将界面更改为:
image: { [key: string]: Images};
And in HTML i use the key of the desired string:在 HTML 中,我使用所需字符串的键:
<ion-img src="{{movie.image.medium}}"></ion-img>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.