垫步进器中的输入具有第一个输入的值

时间:2019-10-19 15:47:42

标签: angular angular-material

Mat Stepper的代码

<mat-horizontal-stepper [linear]="isLinear" #stepper>
    <mat-step [stepControl]="firstFormGroup" >
        <form [formGroup]="firstFormGroup">
            <ng-template matStepLabel>Driver Details</ng-template>
            <mat-form-field class="form-field-full-width">
                <input [(ngModel)]="driverName" matInput placeholder="Name"  formControlName="firstCtrl" required>
            </mat-form-field><br>
            <mat-form-field class="form-field-full-width">
                <input [(ngModel)]="driverEmail" matInput placeholder="Email" formControlName="firstCtrl" required>
            </mat-form-field><br>
            ...
        </form>
    </mat-step>
    <mat-step [stepControl]="secondFormGroup">
        <form [formGroup]="secondFormGroup">
            .....
        </form>
    </mat-step>
</mat-horizontal-stepper>

这就是我将值设置为输入的方式

ngAfterViewInit(){
    this.route.queryParams.subscribe(params => {
    var driverDetails;
    driverDetails = JSON.parse(params['driver']);
    this.driverName = driverDetails['name'];
    this.driverEmail = driverDetails['email'];
    ...
    this.cdRef.detectChanges();
});

重新加载页面后,所有输入的值均为 driverName 。我该如何解决?

1 个答案:

答案 0 :(得分:0)

发现错误。我已经使用了相同的formControlName进行外翻输入。