代码之家  ›  专栏  ›  技术社区  ›  Curtis

角垫选择多个选择更改查找更改了哪个选项

  •  12
  • Curtis  · 技术社区  · 7 年前

    我有一个 <mat select> multiple 选项集(多选)。当 selectionChange 事件激发我需要知道哪个选项已选中或未选中,但是,它只返回选定选项的新当前列表。

    例如,我有一个列表:

    <mat-select (selectionChange)="change($event)" multiple placeholder="Select">
      <mat-option value="1">one</mat-option>
      <mat-option value="2">two</mat-option>
      <mat-option value="3">three</mat-option>
      <mat-option value="4">four</mat-option>
    </mat-select>
    

    if选项 one , three four 选中,然后用户取消选中选项 ,在事件处理程序中,我需要知道哪个选项触发了事件(即,选项 )以及它的新状态。我现在看不到在 选择更改 事件。

    https://stackblitz.com/edit/angular-1e9gsd?file=app/select-overview-example.ts

    我试着把事件处理程序 (selectionChange)="change($event)" <mat-option> 但似乎没有得到支持。

    2 回复  |  直到 6 年前
        1
  •  23
  •   Curtis    7 年前

    我需要使用 onSelectionChange <mat-option> ,这与 selectionChange 你可以用在 <mat-select>

    如果能在 mat-select .

    它在这里工作 https://stackblitz.com/edit/angular-1e9gsd-34hrwg?file=app/select-overview-example.html

        2
  •  -1
  •   Plasty Grove    6 年前

    这对我有效。 blahs 在本例中是字符串数组。使用 2-way binding :

    <mat-select placeholder="choose..." [(value)]="selected" 
          (selectionChange)="somethingChanged(selected)">
      <mat-option *ngFor="let b of blahs; index as i;" value={{b[i]}}">{{b[i]}}
      </mat-option>
    </mat-select>
    
    推荐文章