If I do something like this:
component.html
<input type="button" (click)="emit()">Click to start emitting!</input>
{{decimalNumber | number:'1.1-1'}}
component.ts
ngOnInit(): void {
this.myService.decimalNumberEmitter$.subscribe(value => {
console.log('New value is', value);
this.decimalNumber = value;
});
}
emit(){
this.myService.startEmitting();
}
myService.service.ts
decimalNumberEmitter$ = new BehaviorSubject<number>(0.0);
startEmitting() {
for (let index = 1; index < 11; index++) {
this.decimalNumberEmitter$.next(index / 10);
}
}
Once the previous code is executed console logs:
New value is 0
New value is 0.1
...
New value is 1
However variable (decimalNumber) is not getting updated at all. Its value is 0.0.
I've tried doing something like following in my component html but with no luck:
{{this.myService.decimalNumberEmitter$ | async }}
Also I tried manually detecting the change but with no luck as well - something like following:
constructor(private cd: ChangeDetectorRef) {}
...
... .subscribe( () => {
[my code]
this.cd.markForCheck();
}
Anyone can shed some light on this?? Thanks in advance for any help!
ChangeDetectionasOnPush?