【问题标题】:Angular: can components of an imported module access the services provided in the parent module?Angular:导入模块的组件可以访问父模块中提供的服务吗?
【发布时间】:2020-10-14 06:09:51
【问题描述】:

如果我有带有组件-A 的模块-A 和带有服务-B 的模块-B,并且我将模块-A 导入到模块-B 中,组件-A 是否能够访问服务-B?

【问题讨论】:

    标签: angular angular-services angular-module


    【解决方案1】:

    不,当将模块 A 导入 B 时,模块 B 可以访问模块 A,反之则不行。

    尽管模块声明的所有组件都可以访问服务,但它不适用于导入模块的组件,因为一个简单的事实是,无论使用它们的位置如何,它们仍然存在于它们所在的模块 A 的上下文中无法访问模块 B 的服务。

    【讨论】:

      猜你喜欢
      • 2017-12-11
      • 2018-03-27
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 2019-04-23
      • 2019-05-29
      • 2015-10-26
      • 2017-01-29
      相关资源
      最近更新 更多