angular2 reactiveforms:formGroup 需要一个 FormGroup 实例
angular2 reactiveforms: formGroup expects a FormGroup instance
我无法让我的 child-formgroup 工作。找不到原因。。
我在控制台中看到的错误是:"formGroup expects a FormGroup instance."
我的组件
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>
您的嵌套表单组应该是:
<div formGroupName="passwords">
而不是
<div [formGroup]="passwords">
这是一个
Plunker
我无法让我的 child-formgroup 工作。找不到原因。。 我在控制台中看到的错误是:"formGroup expects a FormGroup instance."
我的组件
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>
您的嵌套表单组应该是:
<div formGroupName="passwords">
而不是
<div [formGroup]="passwords">
这是一个