如何从Mat-Select中获得取消选择的值

时间:2019-01-10 09:34:39

标签: angular typescript angular-material

我有一个垫子桌子,桌子里面有这个垫子选择:

[Fact]
public void GetDefaultTest()
{
    // Arrange
    var type = typeof(DateTime);

    // Act
    var defaultValue = type.GetDefault();

    // Assert
    defaultValue.Should().Be(default(DateTime));
}

我需要获取被取消选择的值,因此我可以将其从选定值的列表中删除,因为表中的每一行都保存在“ selectionChange”上的一个变量中。

3 个答案:

答案 0 :(得分:0)

在HTML方面

(selectionChange)="selectionChange($event)"

在ts上

selectionChange(event: MatSelectChange) {
      console.log(event.value)
}

其中值是对象(数组)列表

答案 1 :(得分:0)

  

我需要获取已取消选择的值,以便可以将其从中删除   所选值的列表,因为表中的每一行都保存在   “ selectionChange”上有一个变量。

为什么? Angular为您工作。使用[(ngModel)]或FormControl

<mat-form-field>
  <mat-select placeholder="Toppings" [(ngModel)]="toppings" multiple>
    <mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option>
  </mat-select>
</mat-form-field>
{{toppings|json}}

//in your .ts
toppings:any[]=[]

<mat-form-field>
  <mat-select placeholder="Toppings" [(formControl)]="toppings" multiple>
    <mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option>
  </mat-select>
</mat-form-field>
{{toppings.value|json}}
//in your .ts
  toppings = new FormControl();

答案 2 :(得分:0)

我知道了。我需要取消选择的值,因为我有更多具有相同ngModel / value的垫选择。为了解决这个问题,我使用了SelectionModel Class

相关问题