我正在使用Angular 6和NgRX 6。
我有一个看起来像这样的减速器-
export interface IFlexBenefitTemplateState {
original: IFlexBenefitTemplate;
changes: IFlexBenefitTemplate;
count: number;
loading: boolean;
}
export const INITIAL_STATE: IFlexBenefitTemplateState = {
original: null,
changes: null,
count: 0,
loading: true,
};
export default (state = INITIAL_STATE, { type, payload }) => {
switch (type) {
case STAGE_TEMPLATE_CHANGE:
const pendingChanges = Object.assign({}, state.changes.sections);
const newSection = Object.assign({}, pendingChanges[payload.key], payload, {
changeType: 'updated',
});
return {
...state,
changes: {
sections: Object.assign({}, pendingChanges, { [payload.key]: { ...newSection } }),
},
count: !pendingChanges[payload.key].hasOwnProperty('changeType') ? state.count + 1 : state.count,
};
default:
return state;
}
};
我有一个选择器,它为我抓住了state.count
,看起来像这样-
export const changesCount = createSelector(getStore, (state: IFlexBenefitTemplateState) => state.count);
我正在尝试显示这是我的模板,如下所示-
@Component({
selector: 'app-page-header-component',
templateUrl: './page-header.component.html',
})
export class PageHeaderComponent implements OnInit {
public count$: Observable<number>;
public language: string;
constructor(private store: Store<ICommonAppState>) {}
ngOnInit(): void {
this.count$ = this.store.select(changesCount);
this.language = 'English';
}
}
this.count$
返回错误
[ts] Argument of type 'MemoizedSelector<IBenefitsState, number>' is not assignable to parameter of type 'string'.
我一生无法理解这是怎么回事?
答案 0 :(得分:5)
我会检查您是否在store
注入中传递了正确的接口。
IFlexBenefitTemplateState
上是否存在ICommonAppState
?
答案 1 :(得分:0)
我有同样的错误。问题出在我的商店中没有错误的界面。相反,我使用了错误的选择器。
感谢@nodediggity使我朝正确的方向看。