I am working with a reactive form and I am able to append some values from it in order to send an http request make a post. It works when I append text or a file, but I am not sure how to append a date or a boolean or an array.
addPost(postAdded: Post, image: File) {
const postData = new FormData();
postData.append("title", postAdded.title); // string
postAdded.append("startDate", postAdded.startDate); // date
postAdded.append("private", postAdded.private); // boolean
postAdded.append("image", image, postAdded.title); // file
this.http
.post<{ postId: string }>(
"http://localhost:3000/api/posts",
postAdded
)
.subscribe(responseData => {
this.potsUpdated.next([...this.posts]);
this.router.navigate(["/"]);
});
}
The error I get is the following:
Argument of type 'Date' is not assignable to parameter of type 'string | Blob'. Type 'Date' is not assignable to type 'string'.ts(2345)
or
Argument of type 'boolean' is not assignable to parameter of type 'string | Blob'.ts(2345)
and finally the error for array
Argument of type 'string[]' is not assignable to parameter of type 'string | Blob'. Type 'string[]' is not assignable to type 'string'.ts(2345)
When using a boolean
The booleans are for toggles, dates for datepickers.
How could I do it?
postData, but you're appending tobetData. Where is that getting declared?