Angular ngRx Store-Reducer返回未定义的-Store.select()未定义
这是我第一次使用ngRx商店,我实现了我的第一个效果 什么是好的:Angular ngRx Store-Reducer返回未定义的-Store.select()未定义,angular,typescript,ngrx,ngrx-effects,ngrx-reducers,Angular,Typescript,Ngrx,Ngrx Effects,Ngrx Reducers,这是我第一次使用ngRx商店,我实现了我的第一个效果 什么是好的: 与后端的通信 正在后端执行操作(删除、添加、获取) 有效载荷从效应到达减速器(确保记录) 所以我的问题是我不能从我的减速器中获取数据。 如果从组件中的存储区中选择数据,则会在组件中获得未定义的数据。我点击了特效中的数据,数据被明确传递。 还记录了减速器中的数据-它就在那里。但是当它被返回时,它返回未定义。 ReDux Devtools可以很好地记录所有内容。最后但并非最不重要。。即使使用固定值,状态也不会更新,例如加载时使用
- 与后端的通信
- 正在后端执行操作(删除、添加、获取)
- 有效载荷从效应到达减速器(确保记录)
export class ProfileComponent implements OnInit {
user: any;
items$: Observable<Product[]>;
loading$: Observable<boolean>;
error$: Observable<Error>;
newItem: Product = {id: 0, name:""};
constructor(private keycloakService: KeycloakService, private store: Store<ProductState>, private productService: ProductService) { }
ngOnInit(): void {
this.productService.setToken(this.keycloakService.getToken());
this.user = this.keycloakService.getUsername();
this.items$ = this.store.select(store => store.list);
this.loading$ = this.store.select( store => store.loading);
this.error$ = this.store.select( store => store.error);
this.store.dispatch(new LoadProduct());
this.items$.subscribe(val => console.log(val));
this.loading$.subscribe(val => console.log(val));
this.error$.subscribe(val => console.log(val));
}
非常感谢您的帮助:)您应该使用选择器功能从商店获取数据: 为了快速解除阻止,我打赌
状态
上未定义列表、.loading、.error
尝试以下方法进行调试:
// see how the whole store looks like
this.store.subscribe(state => console.log({ state }));
对你来说,我看到它与产品相关,所以我打赌它应该是这样的:
this.items$ = this.store.select(store => store.products.list);
this.loading$ = this.store.select( store => store.products.loading);
this.error$ = this.store.select( store => store.products.error);
this.items$ = this.store.select(store => store.products.list);
this.loading$ = this.store.select( store => store.products.loading);
this.error$ = this.store.select( store => store.products.error);