1
votes

I have an error when I open my form on Angular, it is throwing me the next: ERROR TypeError: can't assign to property "validator" on "Email": not an object I don't know why, I also delete the validators and it still throwing from console, so I'm not sure why it happens, my code html is the next:

<form *ngIf="isVisibleFormMember" [formGroup]="formAddMember">
    <div class="form-row">
      <div class="form-group col-md-12">
        <label for="TeamChoose"
          ><i class="fa fa-users text-default"></i> Equipo</label
        >
        <select
          class="form-control form-control-sm"
          formControlName="TeamChoosen"
          id="TeamChoosen"
          name="TeamChoosen"
        >
          <option value="">Choose a team</option>
          <option value="">Choose a team</option>
          <option value="">Choose a team</option>
          <option value="">Choose a team</option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <label for="inputEmails"
        ><i class="fa fa-at text-default"></i> Email</label
      >

      <nz-select  formControl="Email" class="form-control form-control-sm" nzMode="tags" nzPlaceHolder="[email protected]" name="inputEmails"  id="inputEmails">
        <nz-option *ngFor="let option of listOfOption" [nzLabel]="option.label" [nzValue]="option.value"></nz-option>
      </nz-select> 
    </div>
  </form>

And My Ts:

 InitForms(): void {
    this.formAddMember = this._fb.group({
      TeamChoosen: new FormControl('', [Validators.required]),
      Email: new FormControl('', [Validators.required,  Validators.email]),
    });
  }
  ngOnInit(): void {
    this.InitForms();
    this.currentUser = JSON.parse(localStorage.getItem("_u"));
    const children: Array<{ label: string; value: string }> = [];
    for (let i = 10; i < 36; i++) {
      children.push({ label: i.toString(36) + i, value: i.toString(36) + i });
    }

So what I should change for not get this error?

If I Change for formControlName, I get the next error: enter image description here

1

1 Answers

2
votes

You should be using formControlName="Email" instead of formControl.

Also while using nzMode="tags" you should provide an array or null as initial value.

 Email: new FormControl(null, [Validators.required,  Validators.email]),

or

Email: new FormControl(['Initial value'], [Validators.required,  Validators.email]),