我用 angular 和 ngrx 开发应用程序。
如何在功能模块中获取状态?
this.todos$ = this.store.select(state => state.todos.data)
我使用本教程,但我不明白什么是fromStore
我用 angular 和 ngrx 开发应用程序。
如何在功能模块中获取状态?
this.todos$ = this.store.select(state => state.todos.data)
我使用本教程,但我不明白什么是fromStore
如果你的 reducer.ts 导出
export function myList(state = [], action: Action) {
switch (action.type) {
case 1:
return data1;
case 2:
return data2;
default:
return state;
}
}
您的 store.model.ts 必须是这样的:
export interface AppStore {
myList: element[];
...
}
你可以得到这样的状态:
constructor(private store: Store<AppStore>) {}
this.todos$ = this.store.select("myList")
这将返回一个 Observable 元素数组