angular - Angular v8 中的 HTTP 发布并出现打字稿错误
问题描述
我目前收到一条错误消息,上面写着.... event.id 未知
“'HttpResponse' 类型上不存在属性 'id'。”
我有以下界面:
interface UploadPostResponse {
id: string;
}
这是我的 POST 调用...配置只是 POST 和一些附加到它的参数
return this.httpClient.request( config )
.subscribe(event => {
if (event instanceof HttpResponse) {
this.router.navigate(['/inbox'], { queryParams: { inboxName: event.id } });
}
});
我不确定将“UploadPostResponse”接口放在哪里,这样收件箱名称的 event.id 就可以了。
编辑:
const config = new HttpRequest('POST', `${postUrl}`,{file: inbox});
解决方案
响应负载位于响应的body
属性中。你应该id
从event.body.id
.
return this.httpClient.request( config )
.subscribe(event => {
if (event instanceof HttpResponse) {
this.router.navigate(['/inbox'], { queryParams: { inboxName: event.body.id } });
}
});
如果使用,您将直接查询返回的对象httpClient.post
。
return this.httpClient.post(postUrl, {file: inbox})
.subscribe((response: any) => {
this.router.navigate(['/inbox'], { queryParams: { inboxName: response.id } });
});
推荐阅读
- go - 在 Golang 中使用 UserMigration Lambda 设置 AWS Cognito PreventUserExistenceErrors
- symfony - 在 Symfony 4 中为路由配置默认主机
- memory - 如何决定 Gem5 中的 Masterport 和 Slaveport 哪个是 Masterport 和 Slaveport
- c# - React-Native 应用程序异步数据检索无法正常工作
- vb.net - DataGridView 如何打印文本对齐中心和字体大小更改 VB.NET
- react-admin - 在任何地方注入列表、显示、编辑、创建
- c# - 安全条纹支付
- c++ - C++ int* 和 char* 字节顺序交换
- angular - 赛普拉斯与 nrwl/nx 角度项目的集成
- python - 尝试使用 cygwin 构建 portaudio 扩展后出错