I have implemented a simple BehaviorSubject
,
import {BehaviorSubject} from "rxjs";
class MyWeirdoClass {
constructor() {}
private st: Subject<boolean> = new BehaviorSubject<boolean>(null);
changeSt(val:boolean){
this.st.next(val);
}
val(){
this.st.subscribe(res=>{
if (res){
console.log(res);
}
})
}
stStatus() {
this.val();
this.changeSt(true);
this.val();
this.changeSt(false);
this.val();
}
}
now when running stStatus()
gives logs the following output on the console.
true
true
while I expect the value
false
true
false
What is wrong with my implementation?
reload$
, which for some reason does not work:this.reload$.pipe(filter(reload => reload === true), tap(reload => reload = false)).subscribe([Map API request])
. Even though the value DOES change tofalse
, next time I setreload$
totrue
externally, it shows that it IS stilltrue
, so the triggering does not happen. Don't understand why is that. This does not work either:this.reload$.pipe(filter(reload => reload === true), tap(() => reload$.next(false))).subscribe([Map API request])
. What am I doing wrong here? – Ra