次のように私はそうに対する角度2でGET
要求からの情報の配列を取得しようとしています、私はサービスを作成しました:GETリクエストからデータを取得し、それを処理(角2)
obtainInformation() {
// Obtain authorization token for the request
const authToken = localStorage.getItem('auth_token');
// Configure headers
const headers = new Headers();
headers.append('x-access-token', authToken);
// Execute request
return this.http.get(this.clubInfoUrl, { headers: headers })
.map(res => res.json())
.catch(this.handleError);
}
次のように、私は(簡略化のために、私はコードのみ正確な部分を追加)info.component.ts
からこのサービスを呼び出す:これにより
this.service.obtainInformation()
.subscribe(res=>{
console.log(res);
});
、私は2つの文字列情報の配列(持つオブジェクトを取得します私が処理したいアレイ)が、どのように私は配列を選択できます。
IはJSON.stringify()
と試みたが、私は(例えば)ことができない。club_info
res.club_info.id
通知はアレイであり、IDは、配列の要素の一つです。
お勧めはありますか?
ありがとうございます!
編集:console.log(res)
「console.log(res)」から出力された出力はどれですか? – YairTawil
私はスクリーンショットで投稿を編集しました。ありがとうございました! –
あなたは '' 0 ''とアンダースコアの前にIDを忘れました –