首页 > 解决方案 > Angular 访问组件提供者的效果

问题描述

我正在使用 Angular 7 和 ngrx/store 我有一些逻辑非常复杂的组件。它在组件级别注入不同的服务:providers: [Service1, Service2]. 另外,我有一个动作UpdateComponentPresentation,实际上,我想实现这样的目标:

@Effect({ dispatch: false })
  updatePresentation$ = this.actions$.pipe(
    ofType(UpdateComponentPresentation),
    map((action) => {
      const someComponentId = action.payload.id;
      const service1 = getComponentServiceInstanceById(id);
      this.service.rerender();
    })
  );

那么是否有可能以某种方式进入组件服务的效果实例?应该在组件级别注入服务很重要,因为我可以在页面上同时拥有多个组件。在这些服务中,我有许多与当前组件实例相关的内部数据。

标签: javascriptangularngrxngrx-effects

解决方案


推荐阅读