2

I have defined a form in Angular2 like that:

    this.form = this._formBuilder.group({
        password: ['',Validators.required],
        passwordRepeat: ['',Validators.required]
    });

where

public form:ControlGroup

Which is fine, as:

 _formBuilder = FormBuilder.group(controlsConfig: {
        [key: string]: any;
    }, extra?: {
        [key: string]: any;
    }): modelModule.ControlGroup

it returns ControlGroup.

Now, in my component I am using:

this.user.password = this.passwordEditForm.controls.password.value;

Which throws me compilation error of:

error TS2339: Property 'password' does not exist on type '{ [key: string]: AbstractControl; }'.

Seems like a bug. Any ideas on how I can overcome this issue? I've tried doing so:

export interface FormControlGroup extends ControlGroup{
password:any;
}

But this gives me even 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; }'.
2
  • Which version of Angular2 do you use? Commented Mar 14, 2016 at 13:22
  • angular 2 2.0.0-beta.8 Commented Mar 14, 2016 at 13:32

1 Answer 1

9

replace the following :

this.user.password = this.passwordEditForm.controls.password.value;

with

this.user.password = this.passwordEditForm.controls['password'].value;

It works for me. I thinks it's only a workaround.

Sign up to request clarification or add additional context in comments.

2 Comments

Worked here as well, can check off answer. Thanks dude
Ok, this is a workaroud. What is the solution to these errors?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.