Angular Material -select如何知道对象名称(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();
}

我要做的是捕获被点击对象的Name。

我可以达到添加和额外的参数(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)
.
.
}

最新更新