如何从 select 之外操作 mat-select 倍数?

how to manipulate mat-select multiple from outside of the select?

我有一个垫子 select,其中包含一个合同列表,每次我单击合同时,我将它添加到列表中,以便在垫子下显示它-select。

 <mat-form-field style="width: 100%;">
    <mat-select placeholder="Contrats" formControlName="contrat" multiple>
      <mat-option *ngFor="let contrat of contrats$ | async" [value]="contrat.code" (click)="addContrat(contrat.code,contrat.label)">
        {{ contrat.label }}
      </mat-option>
    </mat-select>
  </mat-form-field>

这是允许我添加合同的功能

public list: any[] = [];
addContrat(code: string, label: string) {
this.list.push({ code, label });
}
removeContract(i: number) {
 this.list.splice(i, 1);
}

这是模板:

<mat-chip-list [multiple]="true">
    <mat-chip style="width:100%" *ngFor="let x of list; let i=index" >
        {{x.code}} -- {{x.label}}
        <mat-icon matChipRemove aria-label="" (click)="removeContract(i)">clear</mat-icon>
    </mat-chip>

  </mat-chip-list>

所以我希望当我点击删除合同时垫子 select 将被更新

我想你可能需要像这样用 "removeable" 属性 装饰你的筹码

<mat-chip *ngFor="let fruit of fruits" [selectable]="selectable"
             [removable]="removable" (removed)="remove(fruit)">
      {{fruit.name}}
      <mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
    </mat-chip>

https://stackblitz.com/angular/ebkrnrqbnne?file=app%2Fchips-input-example.html https://material.angular.io/components/chips/overview#chip-input

否则,如果可以接受简单的解决方案,我认为您可以将点击事件移到芯片上而不是图标上。

 <mat-chip style="width:100%" *ngFor="let x of list; let i=index" (click)="removeContract(i)">