Mohan Gopi Mohan Gopi - 7 days ago 7
HTTP Question

HTTP observable returns undefined/null

i have created providers page and i am having my post and get request in it

here is my services which returns observable

post(url: string,data:any): Observable<any>{

return this.http.post(this.configurator.restServerBaseUrl+url,data)
.map((result:Response)=> {
result.json()
})
}


here is my component code

submit(){
this.rest.post('/validateUser',validateUserObj)
.subscribe((result)=>{
this.logger.debug("checking data of success " +JSON.stringify(result));

});
}
}


here my result is giving me undefined


in my services if i map like this it works fine
.map((result:Response)=>result.json())



if i apply bracket i am getting undefined.


can some one help me in understand the observable i have checked in angula.io but i am feeling difficult to understand there

Answer

The short form returns the result of expression implicitly

(param) => expression;

The long form with brackets supports multiple statements but you have to explicitly return

(param) => { 
  let x = this.doSomething();
  return x; 
}