0
我試圖通過功能模塊(使用ngrx docs)編寫狀態時注入功能減速器。如何在getReducers()中返回reducer的映射:ActionReducerMap <fromFeature.State>?
import { NgModule, InjectionToken } from '@angular/core';
import { StoreModule, ActionReducerMap } from '@ngrx/store';
import * as fromFeature from './reducers';
export const FEATURE_REDUCER_TOKEN = new InjectionToken<ActionReducerMap<fromFeature.State>>('Feature Reducers');
我應該回到這裏嗎?
export function getReducers(): ActionReducerMap<fromFeature.State> {
// map of reducers
return {
};
}
我試圖
export function getReducers(): ActionReducerMap<fromFeature.State> {
// map of reducers
return {
reducerA: FeatureAReducer
};
}
但它給錯誤對象文本只能指定已知特性。
的模塊代碼的其餘部分:
@NgModule({
imports: [
StoreModule.forFeature('feature', FEATURE_REDUCER_TOKEN),
],
providers: [
{
provide: FEATURE_REDUCER_TOKEN,
useFactory: getReducers
}
]
})
export class FeatureModule { }
您打算根據功能有多個'StoreModule'嗎? – Aravind
我有自己的減速器的多個功能。 –