2016-10-24 158 views
2

我想知道是否必须实施ControlValueAccessor才能获得与我自己的组件相同的DefaultValueAccessor行为,还是我可以扩展该类?是否可以扩展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"): 

回答

1

是否包含 '日期选取器' 到你的模块的指令阵列?

+0

是的,它已经注册。 – CSchulz

+0

@CSchulz你可以添加模块的代码吗? – yurzui

+0

加入我的问题。 – CSchulz