无法从效果中调用动作
Am New in Angular和Ngrx商店概念(NGRX和Angular版本为13)。
我正在尝试调用操作表格我的createefect
in fefferess.ts files.ts file
createeefect
方法在这里像这样
loadData$ = createEffect(() => this.actions$.pipe(
ofType('[Data] Load data'),
mergeMap(() => this.myService.getDataApi()
.pipe(
map((data: Data[]) => ({
type: '[Data] Load Success',
payload: { data},
selectedData:data[0],
return setData(selectedData),
}
)),
catchError((error: any) => of({
type: '[Data] Load Failure',
payload: { error },
}
))
))
)
);
在调用一个api,称为getDataapi
。一旦我从后端收到数据后,设置Payod并键入type.finally Am调用setData
,然后从响应中传递拳头值。
setData Action
export const setData = createAction(
'[Data] Set Selected',
props<{ selectedData: Data}>(),
);
错误
预先感谢。
Am new in angular and ngrx store concept(ngrx and angular version is 13).
am trying to call an action form my createEffect
method in effects.ts file
createEffect
method look like this
loadData$ = createEffect(() => this.actions$.pipe(
ofType('[Data] Load data'),
mergeMap(() => this.myService.getDataApi()
.pipe(
map((data: Data[]) => ({
type: '[Data] Load Success',
payload: { data},
selectedData:data[0],
return setData(selectedData),
}
)),
catchError((error: any) => of({
type: '[Data] Load Failure',
payload: { error },
}
))
))
)
);
Here am calling an API called getDataApi
. Once i received the data from back end,setting payod and type.Finally am calling setData
and pass the fist value from response.
SetData action
export const setData = createAction(
'[Data] Set Selected',
props<{ selectedData: Data}>(),
);
error
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码怎么了?这显然是错误的部分:
更改为:
What's up with your code? This is a wrong part obviously:
Change with: