Redux Angular2 订阅
Redux Angular2 subscription
我尝试将 redux 应用于我的应用程序,但无法订阅更改。
分量:
从'../../core/reducers/authorization'导入{USER_SIGN_IN};
this.store.dispatch({ 类型:USER_SIGN_IN,有效载荷:数据:数据[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
我出动了。
组件:
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
}
}
我尝试将 redux 应用于我的应用程序,但无法订阅更改。
分量:
从'../../core/reducers/authorization'导入{USER_SIGN_IN};
this.store.dispatch({ 类型:USER_SIGN_IN,有效载荷:数据:数据[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
我出动了。 组件:
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
}
}