I'm currently getting an error message that says....where the event.id is unknown
"Property 'id' does not exist on type 'HttpResponse'."
I have the interface of:
interface UploadPostResponse {
id: string;
}
this is my POST call...config is just the POST and some params attached to it
return this.httpClient.request( config )
.subscribe(event => {
if (event instanceof HttpResponse) {
this.router.navigate(['/inbox'], { queryParams: { inboxName: event.id } });
}
});
I'm not sure where to put the "UploadPostResponse" interface in so that the event.id for the inboxName will be fine..
EDIT:
const config = new HttpRequest('POST', `${postUrl}`,{file: inbox});
The response payload is in the body
property of the response. You should get the id
from event.body.id
.
return this.httpClient.request( config )
.subscribe(event => {
if (event instanceof HttpResponse) {
this.router.navigate(['/inbox'], { queryParams: { inboxName: event.body.id } });
}
});
You would query the returned object directly if using httpClient.post
.
return this.httpClient.post(postUrl, {file: inbox})
.subscribe((response: any) => {
this.router.navigate(['/inbox'], { queryParams: { inboxName: response.id } });
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.