Service.ts
addTankValues(data:any) {
return this.http.post(this.TankApiUrl + "...", data).pipe(
tap(()=>{
this.RefreshRequired.next();
})
);
}
Subscribing to the httpPost:
SaveTV(){
if(this.TVForm.valid){
console.log(this.TVForm.value);
this.service.addTankValues(this.TVForm.value).subscribe(result=>{
this.TVFormresp=result;
console.log(this.TVFormresp);
this.alert = true;
this.TVForm.reset();
});
}else{
console.log("form not valid");
}
I keep on getting 400 error: bad request when sending post request to my asp.net backend. "one or more validation error occurs.
2
Answers
fIXED this using cors
app/heroes/heroes.service.ts (addHero)
The HttpClient.post() method is similar to get() in that it has a type parameter, which you can use to specify that you expect the server to return data of a given type. The method takes a resource URL and two additional parameters:
Taken from https://angular.io/guide/http