【问题标题】:Pass Parameter into Modules将参数传递给模块
【发布时间】:2017-12-01 11:23:50
【问题描述】:

我有 3 个模块:AddressModule、CustomerModule 和 CustomerReportingModule。

AddressModule 有自己的路由和组件,负责为客户显示/编辑地址。它需要客户/客户 ID 来获取其数据。

CustomerModule 和 CustomerReportingModule 应该重用 AddressModule。

目前我正在考虑为我的 AddressModule 使用延迟加载,但这不是强制性的。

如何将客户/客户 ID 传递到 AddressModule 以便它可以加载其数据?

【问题讨论】:

  • 如何将customerId 存储在应用程序的其余部分,例如CustomerModuleCustomerReportingModule
  • 你不能直接使用路由吗?你在 AddressModule 中查看激活的路由并提取 CustomerID
  • @FredrikLundin - 我在两个模块中都有一个特定的商店,它知道选择了哪个客户。我考虑过使用这个商店,但 AddressModule 必须知道其他模块及其商店。
  • @Jan - 是的,这是一个选项,但我需要知道参数存在于哪个路由父级别,因此我知道我的 AdressModule 中的其他模块。
  • 在模块级别添加的每个提供程序都将在应用程序范围内可用。这意味着如果您在 CustomerModule 中提供商店,您也可以在 AddressModule 中注入它。仅供参考:)

标签: angular


【解决方案1】:

为什么不使用服务在这些模块之间共享数据。您可以在主模块提供程序处导入此服务,因此可以在所有其他模块中使用并共享数据。

服务可以具有设置和获取值的功能,因此您可以在服务中使用这些功能来获取所需的数据

【讨论】:

    猜你喜欢
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 2014-06-16
    • 1970-01-01
    相关资源
    最近更新 更多