我正试图从NGRX的商店中获取价值
这就是我想要做的:
ngOnInit(){
this.store.select('appReducer').subscribe(data => {
console.log('this is the data:' + data);
this.sdk = data.sdk;
this.authentication = data.auth;
});
}
这是数据的样子:
export interface AppData {
sdk: any;
auth: any;
}
但我只能使用(data [x] .var)访问该值如何使用它的密钥访问数据而不是它的位置我想做的是> data.key.var
我该如何实现这一目标?
你需要使用map
来达到这个目的,例如
this.store.select('appReducer')
.subscribe(data=> {
this.dataFromStore= data.map(temp => {
return {
sdk: temp.sdk,
auth: temp.auth
};
});
});
然后你可以使用this.dataFromStore
进行进一步处理
也许不是你问题的真实答案,但你应该看看选择器。您可以在商店顶部看到选择器作为查询。
一些可能有用的链接: