HTTP observable 返回 undefined/null

标签 http angular ionic2 observable

我已经创建了供应商页面,我正在发帖并在其中收到请求

这是我的返回可观察的服务

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

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

这是我的组件代码

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

    });
  }
}

我的结果是 undefined

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

如果我应用括号,我将变得不确定。

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

最佳答案

简写形式隐式返回expression的结果

(param) => expression;

带括号的长格式支持多条语句,但你必须显式return

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

关于HTTP observable 返回 undefined/null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40908126/

相关文章:

angular - 如何从 Angular 2+/Ionic2+ 中的 ionic 输入中移除焦点

java - 无效 session 和无效 session 有什么区别

php - Firefox 将谷歌分析数据(utm)添加到 cookie 中

angular - ionic 2 : How to make ionic 2 slider dynamic

html - 如何将 [ngClass] 用于多个类条件 Angular4

CSS 过渡动画 Jank w/zindex on Mac (Retina)

javascript - 使用JavaScript从客户端浏览器上传到Google Cloud Storage

android - Retrofit返回错误307,在android中调用web服务

android - Ionic 2 - Google map 无法在 Android 设备上运行

angular - 包括 ionic 2/angular 2 的公共(public)标题栏