如何在角材料的步进器中提交表单数据。我是关注角度材料https://material.angular.io/components/stepper/examples的例子。在问这个问题之前我做了很多谷歌搜索,但没有找到任何答案。
RowMapper
我完成了填写两个表格。但在那之后,我没有得到如何获取/提交表单数据。
谢谢你的帮助......: - )
答案 0 :(得分:2)
提交提交按钮和ngSubmit以形成Stepper中具有表单的位置
<button mat-raised-button (click)="isLinear = true" id="toggle-linear">Enable linear mode</button>
<mat-horizontal-stepper [linear]="isLinear" #stepper="matHorizontalStepper">
<mat-step [stepControl]="firstFormGroup">
<form [formGroup]="firstFormGroup" (ngSubmit)="form1()" #formone="ngForm">
<ng-template matStepLabel>Fill out your name</ng-template>
<mat-form-field>
<input matInput placeholder="Last name, First name" formControlName="firstCtrl" required>
</mat-form-field>
<div>
<button type="button" mat-button matStepperNext>Next</button>
<button type="submit" mat-button>submit</button>
</div>
</form>
</mat-step>
<mat-step [stepControl]="secondFormGroup">
<form [formGroup]="secondFormGroup" (ngSubmit)="form2()" #formtwo="ngForm">
<ng-template matStepLabel>Fill out your address</ng-template>
<mat-form-field>
<input matInput placeholder="Address" formControlName="secondCtrl" required>
</mat-form-field>
<div>
<button type="button" mat-button matStepperPrevious>Back</button>
<button type="button" mat-button matStepperNext>Next</button>
<button type="submit" mat-button>submit</button>
</div>
</form>
</mat-step>
<mat-step>
<ng-template matStepLabel>Done</ng-template>
You are now done.
<div>
<button mat-button matStepperPrevious>Back</button>
<button mat-button type="button" (click)="stepper.reset()">Reset</button>
<button mat-button type="button" (click)="formone.ngSubmit.emit();formtwo.ngSubmit.emit()">
submit
</button>
</div>
</mat-step>
</mat-horizontal-stepper>
<强>组件强>
form1(){
console.log(this.firstFormGroup.value);
}
form2(){
console.log(this.secondFormGroup.value);
}