2017-08-24 10 views
-2
ngOnInit() { 
    this.allusers = []; 
    this.authService.getallUsers(this.allusers) 
    .subscribe(
    (response) =>console.log(response), 
    (error) =>console.log(error) 
); 
    console.log(this.users); 
} 

すべてのユーザー(first_name、last_name、email)を読み込もうとしています。 ":" 1" 、 "FIRST_NAME": "renuka"、 "LAST_NAME": "ネイヤー"、 "電子メール": "renukaする@ gmailのAngular2の* ngForの応答データを取得する方法

"[{" IDの下に与えられたように私は結果を取得しています。 "[email protected]"}、{"id": "3"}、{"id": "2"、 "first_name": "renuka"、 "last_name": "nayer" 、 "first name": "renuka"、 "last_name": "nayer"、 "email": "[email protected]"}、{"id": "4"、 "first_name": "Rakesh"、 "last_name" "[email protected]"}、{"id": "5"、 "first_name": "Rakesh"、 "last_name": "R"、 "email": "rakeshjack7 + [email protected] "}]"

親切

するレコードを取得するのに役立ち

+0

[非同期呼び出しからの応答を返すにはどうすればよいですか?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous- call) – Igor

+1

上記のコードでは、データは 'response'として到着します。どうしたの? – BeetleJuice

+0

ここでngForはどこですか? – Vega

答えて

1
http 
    .get('Some Url') 
    .map(res => { 
     return res.json(); 
    }) 
    .subscribe(
    (data) => this.data = data, // Reach here mapped data 
    (err) => this.error = err); // fail 
簡略化のために10

、マップメソッドを使用してデータを取得します。

関連する問題