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

前端 未结 21 1292
广开言路
广开言路 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:36

    according to this article

    It turns out we can easily add caching to the observable by adding publishReplay(1) and refCount.

    so inside if statements just append

    .publishReplay(1)
    .refCount();
    

    to .map(...)

提交回复
热议问题