Hello,
I’m trying to figure out how to validate the requiredLength but it keeps crashing on this point.
point of issue is at this line:
required length 3 test
Any ideas as to what I’m doing wrong?
This is my input field:
<input type="text"
class="form-control"
id="userName"
placeholder="userName"
formControlName="userName">
</div>
<div *ngIf="myForm.controls.userName.touched && myForm.controls.userName?.errors?.required" >req. field</div>
<div *ngIf="myForm.controls.userName.errors.minlength.requiredLength"> required length 3 test </div>
Angular 2 script:
ngOnInit(){
this.myForm = this._fb.group({
userName: ['', [Validators.required, Validators.minLength(3)]],
password: ['pwd',Validators.required]
})
}
onSubmitLogin(x){
console.log(x);
}
Error message received:
core.umd.js:3462 EXCEPTION: Error in app/views/user-login.component.html:23:25 caused by: Cannot read property ‘requiredLength’ of undefined