Search code examples
angularangular2-templateangular2-formsangular2-formbuilder

FormControl in Angular 2


I asked the question: Analogue of Angular 2 Provider

But after update angular to rc.4 and @angular/forms to 0.2.0 it doesn't work anymore.

Part of template:

    <form [formGroup]="formGroup">
        ...
        <checkbox-view  [formControl]="formGroup.find('rememberMe')">Remember me?</checkbox-view>
    </form>

In component:

this.formGroup = this._fromBuilder.group({
     ...
     rememberMe: [this.model.rememberMe]
});

And the error: No value accessor for ''


Solution

  • The property controls has inside a map with all the controls.

    You can just do this:

    <form [formGroup]="formGroup">
        ...
        <checkbox-view  [formControl]="formGroup.controls['rememberMe']">Remember me?</checkbox-view>
    </form>