Pipe RxJS observable to existing subject

后端 未结 1 955
庸人自扰
庸人自扰 2021-01-03 21:15

There is existing subject that is in use:

const fooSubject = new BehaviorSubject(null);

And there is another observable (another subject in

1条回答
  •  借酒劲吻你
    2021-01-03 22:01

    Since Subject is already an observer with methods next(), error() and complete() you can just subscribe it to any Observable:

    const fooSubject = new BehaviorSubject(null);
    
    const barSubject = new Subject();
    barSubject.subscribe(fooSubject);
    
    barSubject.next('bar');
    

    0 讨论(0)
提交回复
热议问题