I have a Angular Reactive Form built with couple of sub-components, all using OnPush strategy. I have also a simple calculation: quantity * rate = total;
If total is <input formControlName="total" /> then it gets updated out-of-the-box even with OnPush.
But I want to display readonly value like:
<div class="number" >
{{ form.controls.total.value | number }}
</div>
Indeed, this does not work with OnPush. I have to use ChangeDetectionRef in component:
constructor(
private cdr: ChangeDetectorRef
) { }
ngOnInit() {
this.form.get('total').valueChanges.subscribe(data => {
this.cdr.markForCheck();
});
}
}
This works. I am just trying to find a bit more elegant and less verbose solution like some built-in pipe or so.
Thanks
pipeanddefaultchange detection strategy?