我正在使用Angular Forms製作帶有電子郵件,密碼和複選框的條款&我的Ionic應用程序中的條件。 我的HTML:Ionic中的Angular 2反應形式複選框驗證
<form [formGroup]="registerForm" (ngSubmit)="register()" class="center">
<ion-item class="input-field">
<ion-input type="email" formControlName="email" placeholder="Email"></ion-input>
</ion-item>
<ion-item class="input-field">
<ion-input type="password" formControlName="password" placeholder="Password" ></ion-input>
</ion-item>
<ion-item no-lines>
<ion-checkbox formControllName="termsAndConditions"></ion-checkbox>
<ion-label>Terms and Conditions</ion-label>
</ion-item>
<button ion-button full type="submit" [disabled]="!registerForm.valid">Register</button>
</form>
和一個簡單的角度分量:
export class RegisterComponent {
registerForm: FormGroup;
email = new FormControl('', [Validators.required, Validators.email]);
password = new FormControl('', [Validators.required]);
termsAndConditions = new FormControl('', [Validators.required]);
constructor(private formBuilder: FormBuilder) {
this.registerForm = this.formBuilder.group({
email: this.email,
password: this.password,
termsAndConditions: this.termsAndConditions
});
}
}
我有一個複選框,確認一個問題,因爲我認爲它應該不工作。現在我可以在沒有複選框的情況下提交表單。我只需要使其成爲必需 - 與已經工作的其他表單值相同,我該怎麼做?