检索选项时如何设置mat-select的默认值?

时间:2019-01-31 15:14:45

标签: angular5 angular-material-5

 <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来的多选下拉列表?

1 个答案:

答案 0 :(得分:1)

如果您要设置选定的值,则可以

$('.add-to-cart').click(function() {
    var quantity = 1;
    var clickedProdId = $(this).attr('data-val');
    var id = $('#hidden_'+ clickedProdId).val();
    alert("Product id is " + id + " and quantity is: " +quantity);
});

有关完整示例,请参见https://github.com/bithost-gmbh/ngx-mat-select-search/blob/master/src/app/examples/02-multiple-selection-example/multiple-selection-example.component.ts