How is it possible to post form data to an external rest api?
At the moment i have an html form:
<form [formGroup] = "form" (ngSubmit) = "onSubmit(form.value)">
<input name="name" formControlName="name">
<input name="first_name" formControlName="first_name">
<input name="last_name" formControlName="last_name">
<button type="submit">Save</button>
</form>
and then i have the function that is handling the submit in my component.ts file:
onSubmit = function (user) {
console.log(user);
//this.http.post('http://xxx/externalapi/add', user);
}
But how is it possible to post the form data to my external api? And what is the standard of sending form data with angular? Is it just a simple post request with form data as queryParams or is it standard to convert it into JSON. I can modify the api to handle whatever data is sent so thats not a problem.
.post()
method attaches the value to the body of the request. That means it has to be parsed from the body, and will not come from the query string. This configuration can be determined at your API level.import
the Http package from '@angular/http' at the top of your file, and then use the DI engine to inject it into that component inside of the constructor viaprivate _http: Http
?