I am creating some inputs based on the value of another input, my problem is I don't know how to get the value of these new inputs that are generated.
This is my View Part:
<div class="input-group">
<div class="input-group-append">
<button class="btn btn-secondary" (click)="minusInv()" type="button">
<i class="fa fa-minus">
</i>
</button>
</div>
<input formControlName="inventario" [value]="quantityInv">
<div class="input-group-append">
<button class="btn btn-secondary" (click)="plusInv()" type="button">
<i class="fa fa-plus">
</i>
</button>
</div>
</div>
<ng-container *ngFor="let values of valuesArr; let i= index">
<div class="form-group" style="float:left; margin: 5px;">
<input
placeholder="{{values}}.-"
style="background-color: #e6e9ed;" class="form-control"
type="text">
</div>
</ng-container>
And in my controller part, functions plusInv and minusInv fills the inventarioArr which is just a number array that determinates the number of inputs that will be generated, and I don't know how to get the values of these inputs.
Controller:
plusInv()
{
this.quantityInv++;
this.formGroup.controls['inventario'].patchValue(this.quantityInv)
//this.formGroup.controls['ninos'].updateValueAndValidity();
}
minusInv()
{
if(this.quantityInv>1)
{
this.quantityInv--;
}
else
{this.quantityInv}
this.formGroup.controls['inventario'].patchValue(this.quantityInv)
}
How can I get the value of my dynamic inputs?
You create input without any formControl attached to it. In this example i would try to use FormArray where you can push and remove FormControls, than you can get the value of the formControl you want based on its index. There is good article about FormArray on angular-university: https://blog.angular-university.io/angular-form-array/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With