javascript - Undefined in store reducer -


im trying write reducer action in angular ngrx store architecture:

this reducer:

export const registration = (state: any, {type, payload}) => {   switch (type) {     case 'register_user':       console.log('reducer ' + payload, type);       return payload;     default:       return state;   } }; 

and function calling reducer

register(user: registrationuser) {     return this.http.post(global.api_url+'/register', user)       .map(response => response.json())       .map(data => ({type: 'register_user', data}))       .subscribe(action => {this.store.dispatch(action); console.log(action)});   } 

the problem im having in payload undefined.

console.log(action); 

returns object. , console log reducer returns proper action type undefined object 'reducer undefined register_user'

i think need map data payload: data:

register(user: registrationuser) {     return this.http.post(global.api_url+'/register', user)       .map(response => response.json())       .map(data => ({type: 'register_user', payload: data}))       .subscribe(action => {this.store.dispatch(action); console.log(action)});   } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -