【发布时间】:2017-06-15 15:48:50
【问题描述】:
在我的主要组件的 html 模板中,我使用来自已导入模块的组件的元素。当我尝试构建它时,我收到以下错误。
'df-dashboard-widget' is not a known element:
1. If 'df-dashboard-widget' is an Angular component, then verify that it is part of this module.
2. If 'df-dashboard-widget' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
还有这个错误:
ERROR in Template parse errors:
Can't bind to 'options' since it isn't a known property of 'df-dashboard-grid'.
1. If 'df-dashboard-grid' is an Angular component and it has 'options' input, then verify that it is part of this module.
2. If 'df-dashboard-grid' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
我的 HTML 模板如下所示:
<df-dashboard-grid [options]="options">
<df-dashboard-widget [item]="item" *ngFor="let item of dashboard">
<ng-container *ngComponentOutlet="getComponent(item.tag); injector: getProvider(item)"></ng-container>
</df-dashboard-widget>
</df-dashboard-grid>
我已导入具有df-dashboard-grid 组件的模块,并且该组件已导出。 df-dashboard-widget 也会出现同样的问题。还有一个错误表明ngComponentOutlet 不是ng-container 的属性,尽管我已经从Angular 导入了CommonModule。我的主模块装饰器如下所示:
@NgModule({
declarations: [
DashboardComponent
],
imports: [
BrowserModule,
CommonModule,
HttpModule,
DashboardGridModule
].concat(Configuration.initialization.modules),
providers: [],
bootstrap: [DashboardComponent]
})
使用的带有组件装饰器的模块如下所示:
@NgModule({
declarations: [
DashboardGridComponent,
DashboardWidgetComponent,
DashboardGuideComponent,
DashboardPreviewComponent
],
imports: [
CommonModule
],
exports: [DashboardGridComponent, DashboardWidgetComponent],
})
此错误仅在生产模式下发生。在开发模式下,一切正常。
【问题讨论】:
-
导出所有组件
标签: angular angular-cli