#mat-select and get values

1 messages · Page 1 of 1 (latest)

ancient ocean
#
        <mat-form-field appearance="fill">
          <mat-label>Équipe</mat-label>
          <mat-select formControlName="equipe">
 
              <mat-option *ngFor="let data of dataForSelects['equipes']" [value]="data">
                {{data.label}}
              </mat-option>

          </mat-select>
          <mat-error *ngIf="checkErrorForm('equipe', 'required')">L'équipe est obligatoire</mat-error>
        </mat-form-field>
...
form = this._formBuilder.group({
    id:         [''],
    equipe:     ['', [Validators.required,  ],  ],
...

with :

this.form.valueChanges.subscribe((values: any) => {
  console.log(values);   // The values of the MAT-SELECT are missing

Why is this.form.value missing values from all drop-down lists?
Other text field or date values are well recovered

How do I do this?

humble anchor
ancient ocean
#

ooh thanks i try on stackblitz

humble anchor
#

Open the console of your browser, and read the error message. It says:

ERROR Error: formControlName must be used with a parent formGroup directive. You'll want to add a formGroup
directive and pass it an existing FormGroup instance (you can create one in your class).

#

formControlName is used to say: this input is bound to the control named '...', that you'll find inside the parent form group (or form array)