繁体   English   中英

能够使用未导出的另一个模块中的组件

[英]Able to use a component from another module which is not being exported

我能够从路由中的另一个模块导入一个组件,该组件没有被导出。

路由模块

{
    path: 'home',
    component: DashComponent    
}

B路由模块

{
    declarations: [DashComponent],
}

从上面的代码中可以看出, DashComponent没有在 B 路由模块中导出,但我仍然可以在 A 路由模块中使用它而没有任何错误。 为什么 ?

在模块A,必须有export class DashComponent和模块B,你必须直接导入DashComponent使用import { DashComponent } from '../moduleB/dash.component'

现在这是一个完美的js export-import ,所以没有错误。

其次,模块(A) 的导出属性控制另一个模块(B) 将访问的内容,如果它导入此模块(A),则无需单独从该模块(A) 导入所有其他导出,因此使事情变得方便和系统。 但是它不能阻止您直接从其他模块导入导出,就像您所做的一样(但这样做会破坏使用模块的全部意义)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM