In component, i called dataservice method 'login' which calls post api. res.json() is giving correct response. But in component, when i try to access 'data' it is coming as undefined in subscribe. Don't know what i am doing wrong here. Please help.
dataService:
login(username, password): Observable<any>{
let data = { username: username, password: password};
return this.http.post( this.domain + '/webservice/login', data)
.map( (res: Response) => {
res.json()
})
.catch( (error: any) => Observable.throw(error.json().error || 'server error') );
}
component:
callLoginApi() {
this.showLoading = true;
this.dataService.login(this.username,this.password)
.subscribe(data => {
console.log(data);
});
}