Next to this post I can post this result ["1", "2", "3"] but I have another problem.
When I select product, in view show id, 1, 2 and 3, not name of product. like in image
I change function updateForm()
like below:
products: Products[] = [];
updateForm(ev: any, idd: any, componentid: any) {
if (ev.isUserInput) {
if (componentid === 'products_name') {
this.prodId = idd;
for (let i = 0; i < this.products.length; i++) {
if (this.products[i].products_id=== idd) {
console.log(this.products[i].products_name) //in this part I can see product name
this.myForm.controls.products_id.setValue(this.products[i].products_name)
}
}
} else {
console.log('error');
}
}
}
And my html code is Like this:
<div class="row">
<div class="input-field col s10">
<div class="form-group">
<div formArrayName="products_id">
<div *ngFor="let p of myForm.get('products_id').value; let i = index">
<input formControlName="{{i}}" id="products_id" type="text" aria-label="Number" matInput
[matAutocomplete]="auto">
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete" [displayWith]="displayWith">
<mat-option (onSelectionChange)="updateForm($event, pro.products_id, 'products_name')" *ngFor="let pro of filteredProduct | async"
[value]="pro.products_id">
{{pro.products_name}}
</mat-option>
</mat-autocomplete>
<div class="button-left">
<button *ngIf="myForm.controls.products_id.value.length > 1" type="button" class="fa" (click)="onRemoveItem(i)">-</button>
</div>
</div>
</div>
</div>
</div>
<div class="input-field col s2">
<button type="button" class="btn" (click)="onAddItem()">+</button>
</div>
</div>
Any idea please? How to display products_name ?
Thank you!