【问题标题】:Redux Angular2 subscriptionRedux Angular2 订阅
【发布时间】:2017-10-28 16:58:13
【问题描述】:

我尝试将 redux 应用到我的应用,但无法订阅更改。 组件:
从'../../core/reducers/authorization'导入{ USER_SIGN_IN}; this.store.dispatch({ type: USER_SIGN_IN, payload: data: data[0]});

减速器:

import { ActionReducer, Action } from '@ngrx/store';
export const USER_SIGN_IN = 'USER_SIGN_IN';
export function userSingIn(payload: T) {
    return {
        type: 'USER_SIGN_IN',
        payload: payload
    }
}

服务:

this.store.select(state => state.user).subscribe((user)=> {
  console.log('user:', user);
});

应用模块

StoreModule.provideStore({ user : userSingIn }),

My payload object is empty, i don't understand why

There is console log of subscription:
    Object {type: "USER_SIGN_IN", payload: Object}payload: Objectpayload: Objectpayload: undefinedtype: "USER_SIGN_IN"__proto__: Objecttype: "USER_SIGN_IN"__proto__: Objecttype: "USER_SIGN_IN"__proto__: Object

【问题讨论】:

  • 你没有dispatch 任何东西到你的商店。所以它只会是空的
  • @Tanya 如果你想了解更多关于 redux 架构的细节,你可以在 adv 标签下查看这个链接rahulrsingh09.github.io/AngularConcepts - ngrx

标签: angular redux observable reduce subscription


【解决方案1】:

我派人了。 组件:

this.store.dispatch({ type: USER_SIGN_IN, payload: data: data[0]});

问题出在有效载荷对象中。有效负载对象为空。我添加了 action.payload,现在一切正常。 减速器:

export function userSingIn(state, action: Action) {
return {
    type: 'USER_SIGN_IN',
    payload: action.payload
   }
}

【讨论】:

  • 问题已得到解答。
猜你喜欢
  • 1970-01-01
  • 2016-11-17
  • 2017-07-14
  • 1970-01-01
  • 2018-08-03
  • 2017-10-27
  • 1970-01-01
  • 1970-01-01
  • 2018-02-07
相关资源
最近更新 更多