如何使用Ngrx获取商店价值

问题描述 投票:1回答:2

我正试图从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

我该如何实现这一目标?

angular ngrx
2个回答
0
投票

你需要使用map来达到这个目的,例如

 this.store.select('appReducer')
  .subscribe(data=> {
    this.dataFromStore= data.map(temp => {
      return {
        sdk: temp.sdk,
        auth: temp.auth
      };
    });
  });

然后你可以使用this.dataFromStore进行进一步处理


0
投票

也许不是你问题的真实答案,但你应该看看选择器。您可以在商店顶部看到选择器作为查询。

一些可能有用的链接:

© www.soinside.com 2019 - 2024. All rights reserved.