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

eps*_*lon 6 typescript angular

我有一个像

---app.module
-------child1.module
-------child2.module
Run Code Online (Sandbox Code Playgroud)

并且我app-film在两个子模块中都使用了1个公共组件(),我在中声明了一个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.
Run Code Online (Sandbox Code Playgroud)

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

Sur*_*yan 6

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

@NgModule({
   declarations: [ AppFilmComponent ]
   exports: [ AppFilmComponent ]
})
export class SharedModule { }
Run Code Online (Sandbox Code Playgroud)

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

@NgModule({
   ...
   imports: [ SharedModule ]
   ...
})
export class Child1Module { }
Run Code Online (Sandbox Code Playgroud)

@NgModule({
   ...
   imports: [ SharedModule ]
   ...
})
export class Child2Module { }
Run Code Online (Sandbox Code Playgroud)