我在每行数据生成一个下拉列表:
<ng-container matColumnDef="status_change">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Change Status</th>
<td mat-header *matCellDef="let row">
<mat-form-field>
<form [formGroup]="sitStatus">
<mat-select (click)="updateUnitSituationStatus()" formControlName="sitStatusControl" placeholder="Change Status To">
<!-- <mat-option [value]="row.unit_sprotection_status">{{row.unit_sprotection_status}}</mat-option> -->
<mat-option *ngIf="row.unit_sprotection_status!='Active'" value="Active">Active</mat-option>
<mat-option *ngIf="row.unit_sprotection_status!='Inactive'" value="Inactive">Inactive</mat-option>
</mat-select>
</form>
</mat-form-field>
</td>
</ng-container>
我添加了一个事件来获取更改的下拉列表的值。换句话说,如果我在行id 4处更改了drop list的值,我需要更改值,以及行的id,这样我就可以更新我的数据库了。
我使用了(click)
事件,但出现了错误:
错误TypeError:无法读取UnitEditComponent.push中未定义的属性“value”
这是方法:
updateUnitSituationStatus(){
console.log(this.formGroup.controls['sitStatusControl'].value);
}
我试图使用(change)
事件,但也没有发生任何事情。
既然您在sitStatus
使用<form [formGroup]="sitStatus">
表单组,那么您应该在该组中查找控件
this.sitStatus.controls['sitStatusControl'].value
我没有尝试使用Material UI,但我相信它的工作方式与普通的qazxsw poi相同
select
然后在你的<select (change)="onChangeEvent($event)">
<option value="option1">My Options</option>
</select>
.ts