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 service that I can use .next()
on in various places in my service class. I am wondering if this is the proper way to do it:
private myObservable = new Subject<T>();
public myObservable$: Observable<T> = this.myObservable.asObservable();
- The user can subscribe to
myObservable$
- I can use
myObservable.next(...);
It works perfectly but I am experience enough to know that I may just be being an unwitting idiot (RxJS is huge). Is this correct pattern and correct object for said use case?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…