我有这个函数这个API JSON响应(Github API)
[
{
"id": 1,
"name": "grit",
"full_name": "mojombo/grit",
"owner": {
"login": "mojombo",
"id": 1,
"avatar_url": "https://avatars3.githubusercontent.com/u/1?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/mojombo",
"html_url": "https://github.com/mojombo",
"followers_url": "https://api.github.com/users/mojombo/followers",
"following_url": "https://api.github.com/users/mojombo/following{/other_user}",
"gists_url": "https://api.github.com/users/mojombo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mojombo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mojombo/subscriptions",
"organizations_url": "https://api.github.com/users/mojombo/orgs",
"repos_url": "https://api.github.com/users/mojombo/repos",
"events_url": "https://api.github.com/users/mojombo/events{/privacy}",
"received_events_url": "https://api.github.com/users/mojombo/received_events",
"type": "User",
"site_admin": false
},
"private": false,
"html_url": "https://github.com/mojombo/grit",
"description": "**Grit is no longer maintained. Check out libgit2/rugged.** Grit gives you object oriented read/write access to Git repositories via Ruby.",
"fork": false,
...
}
]
在这个函数中,我想将owner.login元素传递给我的函数gotoDetails。有没有简单的方法呢?我尝试了repo.owner.login
和repo.owner['login']
。
<ion-content padding>
<ion-list>
<ion-card *ngFor="let repo of repos" (click)="goToDetails(repo.name, repo.owner['login'])">
<ion-card-header>
{{ repo.name }}
</ion-card-header>
<ion-card-content>
{{ repo.description }}
</ion-card-content>
<ion-icon name="arrow-forward" item-right></ion-icon>
</ion-card>
</ion-list>
</ion-content>
回购模式:
import { User } from '../models/users';
export interface Repos {
name: string,
full_name: string,
owner: User,
private: boolean,
html_url: string,
description: string,
fork: boolean,
url: string
}