Observed against object and asObservable

I study RxJs, I am looking for confirmation or correction according to my assumption.

I am trying to make public reading only observable in a service that I can use .next()in different places of my service class. I am wondering if this is the right thing to do:

private myObservable = new Subject<T>();
public myObservable$: Observable<T> = this.myObservable.asObservable();
  • User can subscribe to myObservable$
  • I can use myObservable.next(...);

It works fine, but I have enough experience to know that I can be just an involuntary idiot (RxJS is huge). Is this the correct template and the correct object for the specified use case?

+6
source share
2 answers

, , . , , . ( Observable), TypeScript:

private myObservable = new Subject<T>();
public myObservable$: Observable<T> = this.myObservable;

myObservable$, myObservable$.next(), TypeScript ( Observable next()).

, RxJS asObservable . .:

. : rxjs ?

+2

Observables, , next() - .

      private sourceName = new Subject<T>();
      name = this.sourceProductName.asObservable();

      sendName(item: T) {
        this.sourceName.next(item);
      }
+2

All Articles