にHTTPレスポンスをマッピングできません。Chromeコンソールに次のコードが返されます。ERROR TypeError: t.json(...).map is not a function
ng serve -prod
とng test --sm=false
は正常に動作します。Interface to
結果をInterfaceのモデルにマップし、HTMLで出力したいと考えています。
....
export interface UsersData {
_id: number;
email: string;
fullName: string;
}
export class RetrieveUsrData {
private issuesUrl = 'http://localhost:4000/users';
getUserDetails(): Observable<UsersData[]> {
return this.http.get(this.issuesUrl)
.map(this.extractData)
}
extractData(result: Response): UsersData[] {
console.log(JSON.stringify(result.json()));
return result.json().map(usr => {
return {
_id: usr.message._id,
email: usr.message.email,
fullName: usr.message.fullName
}
}).subscribe(result => result = result);
}
constructor(private http: Http) {}
}
...
私はいくつかの問題をチェックしています。 mapping a HTTP response to a JSON and then mapping the JSON to a model、とに私のコード/方法を変更:
extractData(result: Response): UsersData[] {
return result.json().map(res => ({
_id:res.message._id,
email:res.message.email,
fullName:res.message.fullName
}) as UsersData)
.subscribe(result => result = result); ;
}
が、私は同じエラーを取得しておきます。
「http:// localhost:4000/users」からの応答は何ですか? API –
@PankajParkar:これは 'http:// localhost:4000/users' APIのレスポンスです: ' {"エラー":false、 "message":[{"_id": "523"、 "email" "fullName": "xxxxx yyyyy"}、{"_id": "594"、 "email": "[email protected]"、 "fullName": "xxxx yyyyy"}、{[email protected] " "_id": "88"、 "email": "[email protected]"、 "fullName": "xxxx yyyyy"}、{"_id": "59"、 "email": "[email protected]" 、 "fullName": "xxxx yyyyy"}]} '。しかし、今修正されました。ありがとう! –
私は同じと思った。 @Fentonはすでにそれに答えました。ありがとう:) –