I have been struggling to submit a form with default values already set in the form field. The HTML code I am using is as follows:
<form #updateEndpointForm="ngForm" (ngSubmit)="updateEndpoint(updateEndpointForm);">
<section class="form-block">
<div class="form-group">
<input type="text" placeholder="id" name="id" [value]="updateEndpointData?.id" [hidden]="true" ngModel required>
</div>
<div class="form-group">
<label for="endPointType">Endpoint Type</label>
<input type="text" placeholder="Endpoint Type" name="endPointType" [value]="updateEndpointData?.endPointType" ngModel required readonly>
</div>
<div class="form-group">
<label for="name">Endpoint Name</label>
<input type="text" placeholder="Endpoint Name" name="name" [value]="updateEndpointData?.name" ngModel required>
</div>
</section>
<button type="submit" class="btn btn-primary">ADD</button>
</form>
Although the data in the corresponding field displays on the HTML page, when I submit the form, the
console.log(updateEndpointForm.value);
output shows it as empty {"id":"","name":"","endPointType":""}
. Only the modified field's value is displayed. My goal is to gather all values from updateEndpointForm
, not just the ones that are modified. How can I achieve this without using two-way binding [(ngModel)]
? Edit: I prefer not to utilize two-way binding.