How to check if form control is valid in Angular programatically?

user33276346 picture user33276346 · May 15, 2017 · Viewed 17k times · Source

I need to check in the component (not in the template) if a control generated by formBuilder is valid. I tried:

if(this.miSpecialForm.controls.miName.dirty){
 console.log('Hi mom!');
}

but I get the error:

Property 'miName' does not exist on type '{ [key: string]: AbstractControl; }'

Answer

Günter Zöchbauer picture Günter Zöchbauer · May 15, 2017
this.miSpecialForm.get('miName').valid