I have created an Angular form following this article (http://blog.ng-book.com/the-ultimate-guide-to-forms-in-angular-2/):
<div *ngFor="let data of somevar.records">
<form #abc_form="ngForm" (ngSubmit)="onSubmit(abc_form.value)">
{{data.id}} // prints 5
<input name="id" type="hidden" value={{data.id}} ngModel>
<input type="radio" name="name" value={{data.id}} ngModel>
<div class="submit-button">
<button type="submit">Save</button>
</div>
</form>
</div>
The data hash in component looks something like:
somevar = {records: [{id: 5}, {id: 6}]}
Here, when I directly interpolate data.id in view it prints 5 in UI. But, when I try assigning it as a value to an hidden input field, it isn't present. Hence, upon form submission ID parameter is not present.
What is wrong here? What is the correct way to pass ID then?
EDIT
I also tried:
<input name="id" type="hidden" [value]="data.id" ngModel>
NOTE The value gets assigned to the hidden field when I remove ngModel:
<input name="id" type="hidden" [value]="data.id">
OR
<input name="id" type="hidden" value={{data.id}}>
Both the above works and creates hidden inputs with values assigned. But, it's not part of ngModel anymore
[ngModel] = "data.id"? - Rahul Singh