【发布时间】:2018-07-13 13:42:31
【问题描述】:
我在 mat-table 中定义了输入字段。我想通过单击 Next 按钮访问 component.ts 文件中的这些值。我已经有一种单击按钮的方法,但想不出一种访问输入值的方法。我也尝试指定 name 属性,但每个输入标签都是相同的。
HTML 代码:
<ng-container matColumnDef="npm">
<mat-header-cell *matHeaderCellDef fxFlex = "15" style="margin-left: 1%;padding-left: 1%;">NPM</mat-header-cell>
<mat-cell *matCellDef="let row" fxFlex = "15">
<span style ="white-space: nowrap">
<input decimal = "true" value= '{{this.selectedAccount.occupancy.npm}}' style ="display:inline-block; width:55%" #npmValueEntered required>
</span>
</mat-cell>
</ng-container>
<button mat-button [disabled] = "stepTwoFormGroup.invalid || overPercentage || disabledButtons" (click)="submit(stepper)" >Next</button>
【问题讨论】:
-
请参阅模板驱动表单:angular.io/guide/forms
-
反应式表单是要走的路:angular.io/guide/reactive-forms