Will de la Vega Will de la Vega - 2 months ago 16
TypeScript Question

Is there an event in Angular2 rc4+ to tell me when a form is valid?

I am using

formGroup
, custom validators, etc. I need to capture in an event handler when the form becomes valid/invalid, not a property, but an actual event in ts code.

I took a look to the documentation but I wasn't able to find something like:
(validityChange)="myEventHandler($event)"


where
validityChange
is just a placeholder for the name of the actual event I am looking for.

Answer

Subscribe to statusChanges

this.myForm.statusChanges
.filter(s => s == 'VALID')
.subscribe(val => onValid())
Comments