0

我正在尝试使此功能选择器起作用。但是选择器不是返回一个数字而是返回整个状态对象(在我的例子中是 CounterState)

这是我的工作示例:https ://stackblitz.com/edit/angular-ivy-ctypd1?file=src%2Fapp%2Fcounter.selectors.ts

我在页面上得到以下输出:Current Count: [object Object]

我在控制台中得到以下输出。

{counter: 1, loaded: true, loading: false}
{counter: 2, loaded: true, loading: false}
{counter: 3, loaded: true, loading: false}

我期待着1,2,3我错过了什么?

问候,

4

1 回答 1

0

这是因为您在注册 reducer 时创建了一个嵌套的树结构。

StoreModule.forFeature(counterFeatureKey, { counter: counterReducer }),

这应该是(或需要调整选择器):

StoreModule.forFeature(counterFeatureKey, counterReducer ),

于 2021-07-02T19:59:04.293 回答