Search code examples
angularangular2-formsangular2-componentsangular2-formbuilder

Analogue of Angular 2 Provider


I have a custom component for checkbox.

const CheckboxValue = new Provider(
        NG_VALUE_ACCESSOR, {
        useExisting: forwardRef(() => CheckboxComponent),
        multi: true
    });

@Component({
               ...
               providers: [CheckboxValue]
           })
export class CheckboxComponent implements ControlValueAccessor {
    ...
}

As I understood in RC3 Provider was marked as deprecated. How I must rewrite my Component so that he working after next update?


Solution

  • It now takes an object like:

    const CheckboxValue = {
        provide: NG_VALUE_ACCESSOR, 
        useExisting: forwardRef(() => CheckboxComponent),
        multi      : true
    }
    

    Update

    If you get "No value accessor for ''" in RC.3 new forms see Custom component binding: No value accessor for ''