Analogue of Angular 2 Provider

2019-02-27 19:49发布

问题:

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?

回答1:

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 ''