I am creating a component where I need to list all the validation rules of an input.
home.component.html
<input-validation>
<input type="text" class="form-control" formControlName="name">
</input-validation>
home.component.ts
export class HomeComponent implements OnInit {
public myForm: FormGroup;
constructor(private _fb: FormBuilder) { }
ngOnInit() {
this.myForm = this._fb.group({
name: ['', [ <any>Validators.minLength(5), <any>Validators.pattern('^[0-9]*$')]],
address: this._fb.group({
street: ['', <any>Validators.required],
postcode: ['8000']
})
});
}
}
For template driven forms I am using
_rawValidators
property of FormControlName.
But I noticed that _rawValidators does always returns empty array for Reactive forms.
As you can see in above example formControlName="name" has two validators here minlength and pattern. Now unless you starts writing in this input, the errors object of FormControl is null.
So if anyone could help me to understand how ReactiveForms works(validates) or where it stores all its validators would be much appreciable.
Thanks