I am running with a problem in which I have a requirement to create dynamic row of inputs on click of Add. I bind my model with element using index and its all working fine.
<div class="row" *ngFor="let field of fieldArray; let i = index">
<div class="col-sm-2 form-group">
<label for="grid-input-19">Service Name</label>
<select class="form-control" name="Service-{{i}}" [(ngModel)]="field.selectedService" #Service="ngModel" (ngModelChange)="onChange($event)">
<option *ngFor="let service of serviceList" [selected]="service.Service == field.selectedService"
[ngValue]="service">
{{service.Service}}
</option>
</select>
</div>
<div class="col-sm-4 form-group">
<div class="form-group">
<label for="grid-input-18">Service Description</label>
<textarea rows="1" name="Description-{{i}}" [(ngModel)]="field.selectedService.Description" required
class="form-control" [readonly]="true"></textarea>
</div>
</div>
<div class="col-sm-1 form-group">
<label>Quantity</label>
<input type="number" min="1" value="1" step="any" name="Quantity-{{i}}" id="daterange-5" [(ngModel)]="field.selectedService.Quantity" required
maxlength="50" class="form-control" (blur)="onQuantityChange($event.target.value)">
</div>
<div class="col-sm-2 form-group">
<label>Price</label>
<input type="number" min="0" value="0" step="any" name="Price-{{i}}" id="daterange-5" [(ngModel)]="field.selectedService.Price" required
maxlength="50" class="form-control" [readonly]="true">
</div>
</div>
</div>
Question is on Quantity change I am calling a function which requires to modify prices. But quantity of every row input is changing all together. Suppose there are three rows of input. So on changing Quantity of first row input. All are deflecting together. What am I doing wrong.
onQuantityChange(quantity) {
// How do I bind the value of row input price which is created dynamically on quantity change
this.field.Price *= parseInt(quantity);
}
Any help would be appreciated !
onQuantityChangemethod signature?Quantitychange