gpt4 book ai didi

angular - Angular 6 中两个具有公共(public)组件的延迟加载模块

转载 作者:太空狗 更新时间:2023-10-29 17:27:22 26 4
gpt4 key购买 nike

我有这样的结构

---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.

堆栈 Blitz https://stackblitz.com/github/ms-dosx86/films

最佳答案

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

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

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

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

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

关于angular - Angular 6 中两个具有公共(public)组件的延迟加载模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51780143/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com