When I run the following code in Chrome console, I get an error:
ERROR TypeError: t.json(...).map is not a function
. However, both ng serve -prod
and ng test --sm=false
work fine.
My goal is to map the result to the model in Interface and display it in 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) {}
}
...
I have been looking into various issues such as mapping a HTTP response to a JSON and then mapping the JSON to a model, and made adjustments to my code/method like so:
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); ;
}
Despite these changes, I am still encountering the same error.