I have a grid in my Angular app where there are buttons in the row and on clicking the button, it opens the respective popup. I have created a service that has a property of BehaviourSubject
i.e popupEventSubject$
.
The issue I am facing is, when I open and close a popup in the row and then open another popup, the previous popup opens along side the current one. The issue I suspect is that since the Subjects
in RxJS
emit the previous values(when subscribed), the BehaviourSubject
in my case is maintaining a queue of the previous events and when a subscribe is called, it displays all the events in the queue i.e open the previous popups.
So, is there a way to clear the 'queue` that is being created ?
Ideally, I am looking for my BehaviourSubject
to work like a AsyncSubject
, I tried replacing BehaviourSubject
with AsyncSubject
but it doesn't seem to emit the initial event. I tried this.popupEventSubject$.emit(null)
in the constructor of my subject service using AsyncSubject
but it still couldn't subscribe.
I thought of unsubscribing the subject when the popup is closed but then no other popups would open since the subject is no longer available.
Also, I want to avoid emitting null
everytime after I emit an event to clear the queue
.