Suppose to have this dropdown:
<p-dropdown [options]="list" [(ngModel)]="code">
<ng-template let-item pTemplate="selectedItem">
{{ item.value }} - {{ item.label }}
</ng-template>
<ng-template let-item pTemplate="item">
{{ item.value }} - {{ item.label }}
</ng-template>
</p-dropdown>
and in my ts I have:
//loadValue in an object that I have just loaded with this attribute({label, value]}
//list is a list with current dropdown list and it is in this way ({label,vale}]
let index= this.list.findIndex(x => x['value'] === this.loadValue['value']);
this.code= this.list[index];
The problem is that list
,loadValue
and index
are correct calculate, but the selectedItem value is not update because it show me the first value of the list but it is not correct result.
You are assigning the item to your ngModel instead of the value. You need to pass the value. This is obviously a problem however if you think it is not getting updated after your assignment you need to debug what's the actual behavior.
this.code= this.list[index].value;