【问题标题】:Is it possible to extend DefaultValueAccessor?是否可以扩展 DefaultValueAccessor?
【发布时间】:2016-10-24 12:21:27
【问题描述】:

我想知道我是否必须为自己的组件实现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"): 

【问题讨论】:

    标签: angular angular2-components


    【解决方案1】:

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

    【讨论】:

    【解决方案2】:

    使用一些较新的 Angular 版本,可以扩展 DefaultValueAccessor 并毫无问题地注册值访问器。

    【讨论】:

      猜你喜欢
      • 2010-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-08
      • 2011-07-30
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多