Hi there! I am just starting out with Angular 6 and I am encountering an issue while trying to post data to a web API. The error message I am getting is:
Error Message: "400 Bad Request: Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)"
I would really appreciate it if someone could point out where I might be making a mistake. Thank you in advance.
Here is my service:
addIncidents(newIncidents: Incidents): Observable<Incidents> {
return this.http.post<Incidents>('api/v1/events', newIncidents, {
headers: new HttpHeaders({
'Content-Type' : 'application/json'
})
});
And here is my component:
saveIncidents(formValues: any): void {
const newIncidents: Incidents = <Incidents>formValues;
console.log(newIncidents);
this.dataStorageService.addIncidents(newIncidents)
.subscribe(
(data: Incidents) => console.log(data),
(err: any) => console.log(err)
);
}
Here is the Incidents Model:
export interface Incidents {
Incident_Start_Time: string;
Title: string;
Description: string;
Ticket: string;
}
Finally, here is the HTML button:
<button type="button" class="btn btn-primary" (click)="saveIncidents()">Submit</button>