I have created form
<div class="clr-row campform">
<form (ngSubmit)="onSubmit(f)" #f="ngForm">
<div class="clr-col-12 gutterpadl gutterpadr">
<h5>List Name</h5>
<input type="text" name="listname" ngModel class="borderfield" required placeholder="Enter List Name">
</div>
<div class="clr-row autobtn">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn">Cancel</button>
</div>
</form>
</div>
TypeScript Code
onSubmit(form: NgForm) {
const list = { 'listname': form.value.listname };
this.dataManage.createList(list).subscribe(response => { console.log(response) });
this.loadData();
}
Service Code
createList(listname) {
return this.httpClient.post(this.baseURL + 'data_list/create', listname, { headers: this.authService.getCredentialHeaders() });
}
When I click on submit button, and I check on browser developer tools section. In the network I see that request was sent twice, first time blank (No any values sent.) and second time with values.
You can see here create
run twice. When I click on first create call
I get the blank response from server, And when I click on second create
call,
I got an array. I am unable to understand why it is sending request first time with blank data and second time with correct data. I only need one call with correct data.