是否可以扩展DefaultValueAccessor?

时间:2016-10-24 12:21:28

标签: angular angular2-components

我想知道是否必须实现ControlValueAccessor以获得与我自己组件的DefaultValueAccessor相同的行为,还是可以扩展该类?

扩展类以模板解析错误结束(是的,组件已经是模块的一部分)。

模块:

@NgModule({
    imports: [
        BrowserModule,
        HttpModule,
        FormsModule,
    ],
    declarations: [
        AppComponent ,
        DatePickerComponent,
    ],
    bootstrap:    [ AppComponent ],
})
export class AppModule { }

成分:

export class DatePickerComponent extends DefaultValueAccessor {

错误:

Unhandled Promise rejection: Template parse errors:
'date-picker' is not a known element:
1. If 'date-picker' is an Angular component, then verify that it is part of this module.
2. If 'date-picker' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
    <div class="col-sm-7">
        <div class="input-group">
            [ERROR ->]<date-picker [name]="beginn" [(ngModel)]="startDate"></date-picker>
        </div>
        <p id="b"): 

2 个答案:

答案 0 :(得分:1)

您是否在模块的指令数组中加入了“日期选择器”?

答案 1 :(得分:0)

使用一些较新的角度版本,可以扩展DefaultValueAccessor并注册值访问器而不会出现任何问题。

相关问题