angular – 使用Core模块中的组件
发布时间:2020-12-17 17:32:32 所属栏目:安全 来源:网络整理
导读:我是Angular2的新手,我在使用im(ex)移植模块时遇到了一些困难. 根据官方风格指南,CoreModule是: CoreModule – import once when the app starts and never import anywhere else. 这是否意味着所有从Core模块导出的东西只能在仅导入它的模块中使用?在某些
我是Angular2的新手,我在使用im(ex)移植模块时遇到了一些困难.
根据官方风格指南,CoreModule是:
这是否意味着所有从Core模块导出的东西只能在仅导入它的模块中使用?在某些子模块中没有办法提供这些东西吗?我创建了虚拟项目来测试这种行为: 虚拟组件: @Component({ selector: 'dummy-component',template: '<h4>Dummy component</h4>',}) export class DummyComponent {} 核心模块: import { DummyComponent } from './dummy.component'; @NgModule({ declarations : [DummyComponent],exports : [DummyComponent] }) export class CoreModule {} App模块(根模块): @NgModule({ declarations: [AppComponent,],imports: [BrowserModule,CoreModule,HomeModule,RoutingModule],exports : [CoreModule],providers: [],bootstrap: [AppComponent] }) export class AppModule { } Home模块声明home组件: @Component({ selector: 'home-component',template: ` <h2>Home component</h2> <dummy-component></dummy-component> ` }) export class HomeComponent {} 当我尝试运行此代码时出现此错误: 'dummy-component' is not a known element 解决方法
如果您想要其他模块中的东西,那么将它放入共享模块(功能模块). CoreModule不是正确的地方.
是的,您需要将模块导入到要使用该模块中的组件,指令或管道的每个模块. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |