6

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; }'
user33276346
  • 773
  • 1
  • 7
  • 19

2 Answers2

9
this.miSpecialForm.get('miName').valid
Günter Zöchbauer
  • 490,478
  • 163
  • 1,733
  • 1,404
5
if(this.miSpecialForm.controls['miName'].valid){
     console.log('Hi mom!');
}
Amit Chigadani
  • 22,665
  • 10
  • 67
  • 83