I have an Angular application where I use RxJS BehaviorSubject to subscribe to a bool value that indicates an "in progress" status.
But I'm only interested in when the state changes and not the current state on subscription.
export class ProgressService {
private InProgress$ = new BehaviorSubject<boolean>(false);
constructor() {}
public getInProgressStateSubject() {
return this.InProgress$;
}
}
...
this.progressService.getInProgressSubject().subscribe((inProgress: boolean) => {
// This will be triggered in the moment of subscription as well as on state chages
if (inProgress) {
// Toggle on state
} else {
// Toggle off state
}
});
I like how it works, I just don't want it to trigger on subscription.
Are there any other similar operators in RxJS that can help me, or can I do it in any other way?
Thanks!
I think there are several options:
Subjectskip(1) to ignore the first valueYou can use ReplaySubject with bufferSize 1 and they only have 1 value and the last.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With