2017-05-28 168 views
0

我嘗試將redux應用於我的應用,但無法訂閱更改。 組件:
從'../../core/reducers/authorization'導入{USER_SIGN_IN}; this.store.dispatch({type:USER_SIGN_IN,payload:data:data [0]});Redux Angular2訂閱

減速機:

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 
+1

你沒有'dispatch'什麼你的店。所以,如果你想獲得終極版架構一些細節,你可以進階選項卡下檢查此鏈接 https://rahulrsingh09.github.io/AngularConcepts/ 它將是空的只有 – Aravind

+0

@Tanya - NGRX –

回答

0

我派遣。 組分:

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 
    } 
} 
+0

問題是回答。 – Tanya