Angular2 http.post gets executed twice

后端 未结 3 2192
旧巷少年郎
旧巷少年郎 2020-12-03 02:26

I came across a weird issue where the Angular2\'s (RC1) Http service executes the http.post call twice. I\'ve debugged my app and I know for a fact this is not a click event

3条回答
  •  被撕碎了的回忆
    2020-12-03 03:10

    The http service returns a cold observable that get executed on every subscribe, you want to convert it to a hot observable that get only executed on the first subscribe and share the same value for subsequent subscribes.

    To convert it all you have to do is share it:

    return this._http.post(this.createURL(this.getCreateURL(), [], params), body, options)
    .map(res => this.handleObjectResponse(res))
    .share();
    

提交回复
热议问题