我的Angular 5代码没有ngrx效果。添加效果并发送HTTP请求后,我无法触发由动作调用的reducer。我的效果就是这个。使用正确的http响应命中此控制台日志。
@Injectable()
export class PropertyEffects {
@Effect({dispatch: false})
propertyFetch$: Observable<Action> = this.actions$//.pipe(
.ofType(PropertyActions.FETCH_ALL_PROPERTIES)
.switchMap(action =>
this.httpClient.get('https://yxalbf1t6l.execute-api.us-east-1.amazonaws.com/dev/todos').pipe(
// If successful, dispatch success action with result
map(data => {
console.log(`Success ${JSON.stringify(data)}, 0, 2)`);
return new PropertyActions.OpenAllProperties(data)
})
)
);
我在下面的OpenAllProperties操作的reducer在使用效果之前被正确调用。有效,它的控制台日志永远不会被击中。
case PropertyListActions.OPEN_ALL_PROPERTIES:
console.log("in reducer, action.payload: " + JSON.stringify(action.payload,null,2))
const openAllProperties = !state.openAllProperties;
return {
...state,
openAllProperties: openAllProperties
}
请帮忙。谢谢!
答案 0 :(得分:4)
答案 1 :(得分:1)
[{"total":2,"details":"Bob,Logan"},{"total":3,"details":"Scott,Jean,Gambit"}]
);