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

2

11

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; }'
Eloquence answered 15/5, 2017 at 6:27 Comment(0)
T
19
this.miSpecialForm.get('miName').valid
Tantalate answered 15/5, 2017 at 6:28 Comment(0)
S
8
if(this.miSpecialForm.controls['miName'].valid){
     console.log('Hi mom!');
}
Suzysuzzy answered 15/5, 2017 at 6:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.