Observable vs Subject and asObservable

前端 未结 2 943
粉色の甜心
粉色の甜心 2020-12-14 02:57

I am learning RxJs, I am seeking confirmation or correction on my assumption.

I am trying to make a public read only observable in a servic

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 04:01

    In project we are using this kind of Observables, this is giving you proper encapsulation to your private observable, but you still can call next() using some public method.

          private sourceName = new Subject();
          name = this.sourceProductName.asObservable();
    
          sendName(item: T) {
            this.sourceName.next(item);
          }
    

提交回复
热议问题