angular 2 应用程序中的功能标志,如何与所有组件共享一个对象

Feature Flags in angular 2 application, how to share an object with all components

我正在尝试在我的 angular2 应用程序中实现功能标志,这样我就可以发布尚未完全准备好生产的功能。现在我有两个市场,英语和德语市场。我想分别控制这些市场上的功能。

我对这些标志应该如何使用的想法:

为了实现其中的一些功能,我尝试在我的 Angular2 应用程序中创建两个 Json 文件。

示例:

{
  "PassengersFeature": {
    "displayed": true
  },
  "VehicleFeature": {
    "displayed": false
  },
  "DateFeature": {
    "displayed": false
  }
}

现在,我只添加了一个值 = "displayed" 来测试。

基于给定的市场 "EN" 或 "DE",我正在加载正确的 json 文件并将其放入我创建的功能对象中。

// When locale is set, load feature flags files.
this.features = this.appService.getFeaturesForLocale();

现在我想与应用程序中的所有其他组件共享此对象。服务是最好的方法吗?或者你可以使用你在 angularJS?

中做的类似 $scope 的东西吗?

截至目前,sharedService 似乎是您场景的最佳选择。其他方法告诉您 Parent/Child、sibling/sibling 组件之间的通信。所以最好的方法是使用 sharedService 并在 bootstrap 函数中初始化它。