我无法让我的 child-formgroup 工作。找不到原因。我在控制台中看到的错误是:“formGroup 需要一个 FormGroup 实例。”
我的组件
constructor(private _formBuilder:FormBuilder) {}
ngOnInit() {
this.form = this._formBuilder.group({
email: ['', [Validators.required, ValidationService.emailValidator]],
oldPassword: ['', [Validators.required, Validators.minLength(6)]],
passwords: this._formBuilder.group({
newPassword: ['', [Validators.required, Validators.minLength(6)]],
confirmPassword: ['', [Validators.required, Validators.minLength(6)]],
}, {validator: ValidationService.areEqual})
});
}
我的 HTML
<form [formGroup]="form">
<div [formGroup]="passwords">
<div class="form-group">
<label>New password</label>
<input formControlName="newPassword" placeholder="Password" type="password">
</div>
<div class="form-group">
<label>Confirm password</label>
<input formControlName="confirmPassword" placeholder="Confirm password" type="password">
</div>
</div>
</form>