【发布时间】:2022-01-05 12:33:37
【问题描述】:
我正在尝试将 id 参数从调度发送到效果,我在 google 中找不到这种情况的任何示例。
这是我已有的代码:
组件:
ngOnInit(): void {
this.packageClass = `type-${this.package.packageType.toLowerCase()}`;
// I set the payload to the action
this.store.dispatch(new LoadClusterInfo({id: this.package.id}));
this.checkStatus();
}
效果(我需要访问值的地方)
@Effect()
getClusterInfo =
this.actions.ofType(resultActions.Type.LOAD_CLUSTER_INFO)
.pipe(
switchMap(() => {
let id = 'HARDCODED_ID';
return this.service.getPackageCluster(id); // Here is where i need the value
}),
map((packageCluster: PackageCluster) => new LoadClusterInfoSuccess(packageCluster)),
catchError((err: Error) => of(new LoadClusterInfoError(err))),
);
最后的动作:
export class LoadClusterInfo implements Action {
readonly type = Type.LOAD_CLUSTER_INFO;
constructor(readonly payload: any) {}
}
如何在效果中访问组件(this.package.id)发送的id?
【问题讨论】:
-
通过
switchMap()所以:switchMap(payload => { .... }) -
谢谢老兄!你拯救了我的一天。
标签: angular ngrx ngrx-effects