目前我使用的商店是功能模块的扁平结构,即:
{
feature_A: {
A:'A',
B:'B'
},
feature_B:{
C:'C',
D:'D'
}
}
但是我想做的是:
{
feature_A: {
A:'A',
B:'B',
feature_B:{
C:'C',
D:'D'
}
}
}
也许是这样的: 应用程序模块
StoreModule.forFeature('feature_A', fromFeature_A.feature_A_Reducers)
StoreModule.forFeature('feature_A.feature_B', fromFeature_B.feature_B_Reducers)
在网上搜索此问题的答案时,除了建议保持功能模块的平面结构外,并没有真正找到真正的答案。
最佳答案
ngrx
中的功能模块只是对象根的直接状态,因此实际上并没有嵌套功能模块的概念。
相反,您可以通过仍然将功能 B 的状态抽象到不同的文件(reducer、 Action 、效果...)中来完成类似的行为,但将其视为功能 A 的子状态。
然后您可以创建一个选择器来访问特定功能 B 的状态:
const selectFeatureA = createFeatureSelector('feature_A');
const selectFeatureB = createSelector(selectFeatureA, (state) => state.feature_B);
关于angular7 - NGRX 相互嵌套多个功能模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57509781/