其他分享
首页 > 其他分享> > Angular NgModule中的declarations和exports定义

Angular NgModule中的declarations和exports定义

作者:互联网

我在app.component.ts的template文件里试图使用另一个Component时,遇到如下错误消息:

app-parent-child is not a known element:

在parent.module.ts定义里,检查exports区域里是否包含了selector app-parent-child对应的Angular Component:ParentChildComponent:

declarations: 定义了该NgModule的组成部分:Components, directives和pipe等。

imports:

module的imports里能导入其他module,这些被导入的module的declarations的Component也可以在发起导入的module里被使用了:

例子:

AppModule导入了ParentModule,因此其能使用后者export区域暴露的Component:

exports:

假设module A 导入了module B,则module A的declarations区域的所有Component,能使用module B的exports区域定义的Component:

更多Jerry的原创文章,尽在:“汪子熙”:

标签:exports,app,declarations,Component,module,导入,NgModule
来源: https://blog.csdn.net/i042416/article/details/113803754