I am using angular 5
In my html I generate the value of a input field using
<input type="number" class="form-control" id="unitCost" name="unitCost" [(ngModel)]="unitCost" placeholder="Average Unit Price">
document.getElementById("unitCost").value = avgVal;
then I want to retrieve that generated value in my component.ts using
this.unitCost = form2.value.unitCost;
But it returns null value. instead if I type any value in the text field it works fine and returns the value I typed. Can I solve this issue?
FormControlin your.tsfile ?[(ngModel)]="unitCost"does not it take care of your requirements.