将formdata与ngrx一起使用
我使用ngrx并尝试提交我的FormData,这是我的代码:
formData = new FormData();
onSubmit() {
this.formData.set('name', this.userForm.get('name')?.value);
this.formData.set('description', this.userForm.get('description')?.value);
this.formData.set('price', this.userForm.get('price')?.value);
this.formData.set('category', this.userForm.get('category')?.value);
this.formData.set('available', this.userForm.get('available')?.value);
this.store.dispatch(AddItem({this.formData} ))
}
当我尝试派遣AddItem操作时,我有一个错误:类型'{this:any; }'不能分配给类型的参数'{item:item; 。
export const AddItem = createAction(
ItemActionsNames.AddItems,
props<{ item: Item }>()
);
I use ngrx and try to submit my formData and this is my code :
formData = new FormData();
onSubmit() {
this.formData.set('name', this.userForm.get('name')?.value);
this.formData.set('description', this.userForm.get('description')?.value);
this.formData.set('price', this.userForm.get('price')?.value);
this.formData.set('category', this.userForm.get('category')?.value);
this.formData.set('available', this.userForm.get('available')?.value);
this.store.dispatch(AddItem({this.formData} ))
}
when I try to dispatch addItem action I have an error : Argument of type '{ this: any; }' is not assignable to parameter of type '{ item: Item; }'.
and the addItem action code is this :
export const AddItem = createAction(
ItemActionsNames.AddItems,
props<{ item: Item }>()
);
so how I can solve this error ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要适应已指定的有效载荷{item:item},以便调度将
期望与您在创建功能中指定的道具中指定的键/值对。
You need to accomodate the payload you've specified {item: Item} so the dispatch will be
It expects a key/value pair as you've specified in your props in the createAction function.