Angular 6在下拉列表中添加更改事件会给出未定义值的错误

问题描述 投票:0回答:2

我在每行数据生成一个下拉列表:

<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)事件,但也没有发生任何事情。

angular angular-material angular6 onchange event-binding
2个回答
1
投票

既然您在sitStatus使用<form [formGroup]="sitStatus">表单组,那么您应该在该组中查找控件

this.sitStatus.controls['sitStatusControl'].value

1
投票

我没有尝试使用Material UI,但我相信它的工作方式与普通的qazxsw poi相同

select

然后在你的<select (change)="onChangeEvent($event)"> <option value="option1">My Options</option> </select>

.ts
© www.soinside.com 2019 - 2024. All rights reserved.