Unable to validate requiredLength in Angular 2

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

I’d say that we need more of your code in order to diagnose this issue.

I’m no Angular expert, so the answer probably won’t come from me, but yeah.

As a side note, should minlength be minLength? Seems like that would match your naming pattern.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.