In my service file, I have a system that alerts about Subjects
. The value is set and then reset to null after 3 seconds using the setTimeout()
method. However, upon adding
changeDetection: ChangeDetectionStrategy.OnPush
to the app.component.ts
, it appears to disrupt the functionality of the SetTimeout()
method. Is there a way to incorporate ChangeDetectorRef
in a service?
storage.service.ts
private errorMsg: Subject < string > = new Subject();
private successMsg: Subject < string > = new Subject();
constructor() {}
setSuccessAlert(msg: string) {
this.successMsg.next(msg);
setTimeout(() => {
this.successMsg.next(null);
}, 3000);
}
Without ChangeDetectionStrategy https://i.sstatic.net/PeoQX.png