Currently, I am facing a problem with my service and component setup. While the service can successfully read the response as a JSON object, the component is returning res: undefined
.
service:
constructor(
private http: Http,
private fbuilder: FormBuilder,
private user: UserService
) {}
login(uname:string, pass:string): Observable<any> {
let headers = new Headers({
'Content-Type': 'application/json',
'Username':uname,
'Password':pass
});
let options = new RequestOptions({ headers: headers });
let data = {};
var Observable = this.http.post( url, data, options )
.map(res => {
res.json();
})
.catch( (error: any) => Observable.throw(error.json().error || 'Server error') );
return Observable;
}
component:
constructor(
private http: Http,
private fbuilder: FormBuilder,
private user: UserService
) {}
loginUser(uname: string, pass: string) {
this.user.login(uname, pass).subscribe(
res => {
console.log('res: ' + JSON.stringify(res));
},
err => {
this.errorMessage = err;
}
);
}