What is the correct way to share the result of an Angular Http network call in RxJs 5?

前端 未结 21 1375
广开言路
广开言路 2020-11-21 06:11

By using Http, we call a method that does a network call and returns an http observable:

getCustomer() {
    return          


        
21条回答
  •  梦谈多话
    2020-11-21 06:25

    Per @Cristian suggestion, this is one way that works well for HTTP observables, that only emit once and then they complete:

    getCustomer() {
        return this.http.get('/someUrl')
            .map(res => res.json()).publishLast().refCount();
    }
    

提交回复
热议问题