私はangular2の新機能です。ここで、getLeftData()の戻り値の型はどのようにして特定の戻り値の型になりますか?
Angular 2タイスクリプトでjsonオブジェクトのListの型を返す方法はありますか?
HTTPTestService.ts:
@Injectable()
export class HTTPTestService {
private siteUrl="https://api.stackexchange.com/2.2/sites";
constructor(private _http: Http) { }
getLeftData(): Promise<Items[]> {
return this._http.get(this.siteUrl).
toPromise()
.then(response =>response.json().data as Items[])
}
}
JSONデータ:
{
"items": [
{
"aliases": [
"http://www.xyz.in",
"http://facebook.xyz.in"
],
"styling": {
"tag_background_color": "#E0EAF1",
"tag_foreground_color": "#3E6D8E",
"link_color": "#0077CC"
},
"related_sites": [
{
"relation": "meta",
"api_site_parameter": "meta.xyz",
"site_url": "http://met.xyz.in"
},
{
"relation": "chat",
"name": "Stack Overflow Chat"
}
],
"markdown_extensions": [
"Prettify"
],
"launch_date": 1221436800,
"closed_beta_date": 1217462400,
"site_state": "normal",
"favicon_url": "https://cdn.sstatic.net/Sites/xyz/img/favicon.ico",
"name": "Stack Overflow",
"site_type": "main_site"
}
]
}
誰が助けるならば、どの角度2 typescriptですでJSONオブジェクトのリストの戻り値の型だろうか?
あなたが代わりに約束の観測を使用する必要があります。これをチェックしてください投稿http://stackoverflow.com/questions/37364973/angular-2-promise-vs-observable – alltej