【发布时间】:2018-02-27 03:56:23
【问题描述】:
我的 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 操作的减速器在使用效果之前被正确调用。实际上,它的控制台日志永远不会被命中。
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
}
请帮忙。谢谢!
【问题讨论】:
-
我认为
{dispatch: false}参数正在阻止传递操作。
标签: angular ngrx ngrx-effects