0

I am trying to use Validators on my form inputs but get this error Cannot create property 'validator' on string 'clientUserName' I would like to resolve this error.

My html

<form [formGroup]= "userInfoForm" (ngSubmit)="onUserInfoFormSubmit()">
  <mat-form-field>                       
     <mat-label>User Name</mat-label>
     <input id="clientUserName" type="text" formControl="clientUserName" matInput>
  </mat-form-field>
</form>

My ts

export class ManageAccountClientComponent implements OnInit {
   userInfoForm: FormGroup;

   constructor(
    private formBuilder: FormBuilder
    ) { }

   ngOnInit(): void {

    this.userInfoForm = this.formBuilder.group({
      clientUserName: ['', Validators.required]
    });
   }
  
   onUserInfoFormSubmit(){
    window.alert('UserInfoFormSubmit');
  }

}

1 Answer 1

1

Change formControl="clientUserName" to formControlName="clientUserName"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.