Reputation: 1819
I have in my view:
<select id="field_cliente" name="cliente"
[(ngModel)]="oportunidad.cliente">
<option [ngValue]="null"></option>
<option [ngValue]="clienteOption" *ngFor="let clienteOption of clientes; trackBy: trackClienteById">{{clienteOption.razonSocial}}</option>
</select>
I have in my controller:
trackClienteById(index: number, item: Cliente) {
return item;
}
The object is:
cliente{
id:"",
razonSocial:""
}
The value loads well when I select one, but when entering if it already has a previous value, it does not fit the value with the "select" and the "select" goes empty, even if the entity has value.
Upvotes: 0
Views: 177
Reputation: 1819
<select [compareWith]="equals" ...
in controller:
equals(o1: Cliente, o2: Cliente) { return o1.id === o2.id; }
Upvotes: 1