Can we again emit a value after completing a Subject object in rxjs?

Viewed 267

I am new to rxjs library and started learning it recently. I have a doubt.

Can we again emit a value after completing a Subject or do we have to again initialize the subject for emitting a value and if we have to again initialize, do previous subscriptions work?

1 Answers

Can we again emit a value after completing

Once an observable completes or errors, it's gone. The same is true for subjects.

do we have to again initialize the subject for emitting a value

You can not re-initialize a subject, but you can create a new one.

if we have to again initialize, do previous subscriptions work?

No, when you create a new subject it has no 'memory' of any subjects you have created before. There's no way for observers to be transferred between observables. That being said, an observer is just an object. So while you can't 'transfer,' you can subscribe the same observer to multiple observables/subjects.

Related