I'm trying to migrate an app to using ChangeDetectionStrategy.OnPush
. However, I'm running into a bit of a blocker trying to work with some reactive forms.
I've got a reusable control that shows validation messages based on some of the state flags (e.g. *ngIf="control.touched && control.invalid"
). The problem I'm running into is that there's no way to detect when the touched
flag changes, and therefore no way to trigger change detection using ChangeDetectorRef
.
It could be done with a reference to the input element itself by listening for a click
event, but that doesn't account for when markAsTouched()
is used, and passing a reference to the element around isn't always possible, and it's always inelegant.
Is there a way to use OnPush
and still respond to the form control state (e.g. touched
), or is it just generally painful?