添加StoreModule.forFeature(…)后无法访问存储的数据

问题描述 投票:2回答:1

我在一个8号角应用程序中有多个项目...到目前为止,我只有一个项目@ngrx/store,但是现在我在每个项目中都添加了@ngrx/store,由于存在多个存储,我需要在每个项目中的app.module中导入StoreModule.forFeature

imports: [
    StoreModule.forRoot({}),
    StoreModule.forFeature("project1store", fromStore.reducer1)
]

在第二个项目中,我导入

 imports: [
        StoreModule.forRoot({}),
        StoreModule.forFeature("project2store", fromStore.reducer2)
    ]

问题是,在redux中,我看到了所有数据,但无法接受。另外,我对每个减速器都出错(所有这种减速器之前都工作过)

store.js:994 @ ngrx / store:状态中不存在功能名称“ UserProfileReducer”,因此createFeatureSelector无法访问它。确保使用StoreModule.forRoot('UserProfileReducer',...)或StoreModule.forFeature('UserProfileReducer',...)将其导入已加载的模块中。如果默认状态是未定义的(如路由器状态一样),则可以忽略此仅开发警告消息。

我使用桶(index.ts)导入所有内容,在这种情况下是从fromStore中导入。每个应用程序都有自己的存储桶,我再次检查,每条路径都可以。

在此图像上看到的所有数据都已存在,但是现在StoreModule.forFeature之后无法接收它enter image description here

编辑:

我认为问题出在这里enter image description here

在此之前,我获得了store.siteReducer之类的数据,但现在我需要像state.app2.siteReducer之类的方式接受它>

如何以及在何处添加此app1app2

Thnx

我在一个angular 8应用程序中有多个项目...直到现在,我在一个项目@ ngrx / store中只有一个项目,但是现在我在每个项目中都添加了@ ngrx / store,并且由于存在多个商店,所以我在每个项目中都需要它。 ..

angular typescript ecmascript-6 redux ngrx
1个回答
0
投票

您需要配置功能选择器以获取嵌套级别状态

export const selectState = createFeatureSelector<ISomeState>(
    "app2"
);

export const selectSomeState = createSelector(
    selectState,
    state => state.someProp.someProp
);
© www.soinside.com 2019 - 2024. All rights reserved.