Angular 2提供程序的类似物 [英] Analogue of Angular 2 Provider

查看:71
本文介绍了Angular 2提供程序的类似物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有复选框的自定义组件。

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 {
    ...
}

据我在RC3 Provider中所理解的,已被标记为已弃用。我该如何重写我的组件,以便他在下一次更新后能够正常工作?

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

推荐答案

它现在需要一个像这样的对象:

It now takes an object like:

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

更新

如果您在RC.3新表格中看到没有值访问器,请参见自定义组件绑定:

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

这篇关于Angular 2提供程序的类似物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆