Service
mode: Subject<any> = new Subject<any>();
constructor(public http: HttpClient) {
this.setMode({ // defaults
admin: this.admins.includes(localStorage.getItem("email")),
edit: false,
dev: false
});
}
getMode() {
return this.mode.asObservable();
}
setMode(value) {
this.mode.next(value);
}
Component
constructor(private bcAuthService: BcAuthService) {}
ngOnInit() {
this.bcAuthService.getMode().subscribe(mode => {
console.log('mode: ', mode); // never logs or prints in the template
this.mode = mode;
});
}
editToggle(e) {
this.mode.edit = e.target.checked; // err: cant edit `mode` because it never set.
this.bcAuthService.mode.next(this.mode);
}
Question
I am trying to set up an Observable to be read and wrote from many components. As seen above; I set up the observable in my service but my component getMode()
doesnt work. Any ideas why?