【问题标题】:Able to use a component from another module which is not being exported能够使用未导出的另一个模块中的组件
【发布时间】:2021-10-18 16:59:21
【问题描述】:

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

路由模块

{
    path: 'home',
    component: DashComponent    
}

B路由模块

{
    declarations: [DashComponent],
}

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

【问题讨论】:

    标签: angular


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-05
      • 2020-07-24
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      • 1970-01-01
      • 2021-09-18
      相关资源
      最近更新 更多