簡體   English   中英

Angular Material mat-select如何知道對象名稱(selectionChange)

[英]Angular Material mat-select how to know object name (selectionChange)

我有兩個這樣的墊子選擇

<mat-form-field>
        <mat-select formControlName="Source" required placeholder="Source" (selectionChange)="change($event)"  [disabled]="!enabled">
          <mat-option *ngFor="let system of apiEntitySyncViewModel.Systems" value="{{system.Value}}">{{system.Text}}</mat-option>
        </mat-select>
        <mat-error>This field is mandatory</mat-error>
      </mat-form-field>

      <mat-form-field>
        <mat-select formControlName="Destination"  placeholder="Data Destination" (selectionChange)="change($event)" [disabled]="!enabled">
          <mat-option *ngFor="let system of apiEntitySyncViewModel.Systems" value="{{system.Value}}">{{system.Text}}</mat-option>
        </mat-select>
      </mat-form-field>

在我的 .ts 中,我做了一些驗證......如果兩者的值都不同於 0.. 一個函數被觸發。 這就是為什么我在(selectionChange)事件上具有相同的功能名稱

這是我的功能..

change( ob:MatSelectChange) {
  var source=this.form.value["Source"];
  var destination=this.form.value["Destination"];
  if(source=="0" || destination=="0")
    return;
  this.getWorkflowItems();
}

我想做的是捕獲被點擊對象的名稱。

我可以達到那個添加和額外的參數(selectionChange)="change($event,'objName')" 但我想知道我是否可以使用 $event 參數...

謝謝

而不是value="{{system.Value}}"傳遞整個對象:

      <mat-form-field>
       <mat-select formControlName="Source" required placeholder="Source" 
                   (selectionChange)="change($event)" [disabled]="!enabled">
          <mat-option *ngFor="let system of apiEntitySyncViewModel.Systems"
                       value="{{system}}">
                {{system.Text}}
          </mat-option>
        </mat-select>
        <mat-error>This field is mandatory</mat-error>
      </mat-form-field>
      .
      .

在 .ts 文件中:

change(ob: MatSelectChange) {
  const source = this.form.value["Source"];
  console.log(source.Value)
  console.log(source.Text)
  .
  .
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM