【发布时间】:2019-10-23 20:15:49
【问题描述】:
我正在使用 Angular Material Stepper 制作入职流程。如果他们选择使用 google 创建帐户,我想要求用户名,但如果他们选择创建帐户的方法,我还想要求提供电子邮件和密码。
<mat-step [stepControl]="createAccountFormGroup" [completed]="createAccountCompleted">
<form [formGroup]="createAccountFormGroup">
<ng-template matStepLabel>Create Account</ng-template>
<h2>Create Your Account</h2>
<div *ngIf="error" class="error">{{ error }}</div>
<div>
<div>
<div>
<mat-form-field>
<mat-label>Name</mat-label>
<input matInput placeholder="John Doe" formControlName="nameCtrl" required />
</mat-form-field>
</div>
<div>
<button
mat-raised-button
color="secondary"
class="register-button"
[disabled]="
createAccountFormGroup.controls.nameCtrl.status !== 'VALID'"
(click)="createAccountWithGoogle(stepper, createAccountFormGroup)"
>
<span class="fab fa-google google-icon"></span>Sign In With Google
</button>
</div>
<div class="or">Or</div>
</div>
<div>
<div>
<mat-form-field>
<mat-label>Email</mat-label>
<input matInput placeholder="johndoe@email.com" formControlName="emailCtrl" required />
</mat-form-field>
</div>
<div>
<mat-form-field>
<mat-label>Password</mat-label>
<input matInput formControlName="passwordCtrl" required type="password" />
</mat-form-field>
</div>
<div class="error">
<span *ngIf="(password.dirty || password.touched) && password.invalid">
Password must be at least 8 characters long with numbers and uppercase and lowercase letters
</span>
</div>
<div>
<button
mat-raised-button
color="primary"
[disabled]="!createAccountFormGroup.valid || loading"
type="submit"
class="register-button"
(click)="createAccountWithEmail(stepper, createAccountFormGroup)"
>
Create Account
</button>
</div>
</div>
</div>
</form>
</mat-step>
</mat-horizontal-stepper>
创建帐户后,我使用 stepper.next() 进入下一步。问题是如果表单无效,Angular Stepper 将不允许您前进。在一种情况下,他们使用谷歌创建帐户,不需要电子邮件和密码,所以我不知道如何强制步进器在没有这两个字段的情况下继续前进。
也许我可以根据他们按下的按钮动态更改需要哪些字段?我也不知道这是否可能。
【问题讨论】: