Skip to content
Advertisement

Unable to post angular form data using web api

contact.component.html

JavaScript

contact.component.ts

JavaScript

api.service.ts

JavaScript

create.php

JavaScript

I am new in angular and I am simply trying to insert angular form data in mysql using web api. Now, What happen here when I try to read data from database it work perfectly and all data are showing in my console. But when I fill form data then it throw an error as mention below.

POST http://localhost/financeAPI/create.php 400 (Bad Request)

ERROR HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: 'Bad Request', url: 'http://localhost/financeAPI/create.php', ok: false, …}

I don’t know why this happen? Please help me to solve this issue.

Thank You

Advertisement

Answer

in your submit button try change

createOrUpdateContact(f)

to

createOrUpdateContact(f.value)

to get the value from your form

JavaScript

I replicate your code Here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement