In Angular2, I have created a form with the following structure:
this.form = this._formBuilder.group({
password: ['',Validators.required],
passwordRepeat: ['',Validators.required]
});
The form
is defined as:
public form:ControlGroup
This setup works because:
_formBuilder = FormBuilder.group(controlsConfig: {
[key: string]: any;
}, extra?: {
[key: string]: any;
}): modelModule.ControlGroup
it returns ControlGroup
.
However, when trying to access the password value in my component like this:
this.user.password = this.passwordEditForm.controls.password.value;
I get a compilation error saying:
error TS2339: Property 'password' does not exist on type '{ [key: string]: AbstractControl; }'.
This issue seems like a bug. Any suggestions on how to resolve it? I attempted the following approach:
export interface FormControlGroup extends ControlGroup{
password:any;
}
But this led to more errors:
error TS1206: Decorators are not valid here.
app/form.component.ts(30,9): error TS2322: Type 'ControlGroup' is not assignable to type 'FormControlGroup'.
Property 'password' is missing in type 'ControlGroup'.
app/form.component.ts(37,61): error TS2339: Property 'password' does not exist on type '{ [key: string]: AbstractControl; }'.