In the service, there is this code :
getUser(id){
return this.http.get(\'http:..../\' + id)
.map(res => res.json());
}
In the
(err)
needs to be outside the customer
fat arrow:
this.myService.getUser(this.id).subscribe((customer) => {
console.log(customer);
this.customer = customer,
},
(err) => {console.log(err)});
To get the error msg back, add a catch
that will return the error object:
getUser(id){
return this.http.get('http:..../' + id)
.map(res => res.json())
.catch(this.handleError);
}
private handleError(error: any) {
let errMsg = (error.message) ? error.message : error.status ? `${error.status} - ${error.statusText}` : 'Server error';
return Observable.throw(error);
}