我试图在角度ngrx商店架构中编写reducer for action:
这是我的减速机:
export const registration = (state: any, {type, payload}) => {
switch (type) {
case 'REGISTER_USER':
console.log('reducer ' + payload, type);
return payload;
default:
return state;
}
};
这是我的函数调用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)});
}
我遇到的问题是有效载荷未定义。
console.log(action);
返回对象。来自reducer的控制台日志返回正确的操作类型但未定义为对象'reducer undefined REGISTER_USER'
答案 0 :(得分:1)
我认为您只需要将数据映射到有效负载: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)});
}