I\'ve a simple question about change detection.
I have a component and a (global) service with a boolean inside. How can I make the component listen to that boolean
The Sam's answer is completely right. I would just want to add that you could also leverage a TypeScript setter to automatically trigger the event for changes:
@Injectable()
export class MyBooleanService {
myBool$: Observable;
private boolSubject: Subject;
constructor() {
this.boolSubject = new Subject();
this.myBool$ = this.boolSubject.asObservable();
}
set myBool(newValue) {
this._myBool = newValue;
this.boolSubject.next(newValue);
}
}