我有一个类似
的结构---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.
答案 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 { }