Angular 6中的两个具有公共组件的延迟加载模块

时间:2018-08-10 06:18:01

标签: angular typescript

我有一个类似

的结构
---app.module
-------child1.module
-------child2.module

并且我在两个子模块中都使用了1个公共组件(app-film),我在app.module中声明了一个,但是Angular仍然显示错误

Can't bind to 'film' since it isn't a known property of 'app-film'.
1. If 'app-film' is an Angular component and it has 'film' input, then verify that it is part of this module.
2. If 'app-film' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

stackblitz https://stackblitz.com/github/ms-dosx86/films

1 个答案:

答案 0 :(得分:3)

嵌套模块将看不到在父模块(导入嵌套模块)中定义的组件。您需要像这样创建SharedModule

@NgModule({
   declarations: [ AppFilmComponent ]
   exports: [ AppFilmComponent ]
})
export class SharedModule { }

从该模块导出AppFilmComponent,然后将SharedModule模块分别导入两个子模块。

@NgModule({
   ...
   imports: [ SharedModule ]
   ...
})
export class Child1Module { }

@NgModule({
   ...
   imports: [ SharedModule ]
   ...
})
export class Child2Module { }