简体   繁体   English

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

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

I'm able to import a component from another module in routing which is not being exported.我能够从路由中的另一个模块导入一个组件,该组件没有被导出。

A routing module路由模块

{
    path: 'home',
    component: DashComponent    
}

B routing module B路由模块

{
    declarations: [DashComponent],
}

As seen in the above code, DashComponent is not being exported in B routing module but still I'm able to use it in A routing module without any errors.从上面的代码中可以看出, DashComponent没有在 B 路由模块中导出,但我仍然可以在 A 路由模块中使用它而没有任何错误。 Why ?为什么 ?

In module A, there must be export class DashComponent and in module B you must be directly importing the DashComponent using import { DashComponent } from '../moduleB/dash.component' .在模块A,必须有export class DashComponent和模块B,你必须直接导入DashComponent使用import { DashComponent } from '../moduleB/dash.component'

Now this is a perfectly fine js export-import , so there is no error.现在这是一个完美的js export-import ,所以没有错误。

Second, the export property of a module(A) controls what the another module(B) will get access to, if it imports this module(A), without you having to import every other export from that module(A) separately, thus making things convenient and systematic.其次,模块(A) 的导出属性控制另一个模块(B) 将访问的内容,如果它导入此模块(A),则无需单独从该模块(A) 导入所有其他导出,因此使事情变得方便和系统。 But it cannot stop you from importing the exports directly from other modules, like you did (but doing this ruins the whole point of using modules).但是它不能阻止您直接从其他模块导入导出,就像您所做的一样(但这样做会破坏使用模块的全部意义)。

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

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