Как установить значение по умолчанию для выбора мата при извлечении параметров?

 <mat-form-field [ngClass]="classes">
  <mat-select [placeholder]="placeholder" [(ngModel)]="selectValue" [multiple]="true" #multiSelect (change)="onChange()"
    #itemSelect="ngModel">
    <ngx-mat-select-search [formControl]="multiFilterCtrl"></ngx-mat-select-search>
    <mat-option *ngFor="let option of filteredMulti | async" [value]="option.id">
      {{option.name}}
    </mat-option>
  </mat-select>
</mat-form-field>

Множественный выбор углового материала, как установить значения для раскрывающегося списка множественного выбора, исходящего из API?


person Tushar    schedule 31.01.2019    source источник


Ответы (1)


если вы пытаетесь установить выбранные значения, вы можете

// ...data coming from the api and saved to this.filteredMulti

this.filteredMulti.take(1).subscribe(() => 
    // set your model
    selectValue = apiData.selectValue

    // setting the compareWith property to a comparison function
    // triggers initializing the selection according to the initial value
    // this needs to be done after the filteredMulti are loaded initially
    // and after the mat-option elements are available
    this.multiSelect.compareWith = (a: number, b: number) => a === b;
});

См. https://github.com/bithost-gmbh/ngx-mat-select-search/blob/master/src/app/examples/02-multiple-selection-example/multiple-selection-example.component.ts для полного примера

person Esteban Gehring    schedule 04.02.2019