Reputation: 45325
I have two objects - Order
and Customer
. Now I want to edit Order
. Order
have two fileds from Customer
object. I want to display list of Customers
in select option:
select(ng-model="customer"
ng-options="customer.description for customer in vm.customers"
ng-change="vm.setCustomer(customer)")
Here is setCustomer()
method in the controller:
setCustomer = function(customer) {
this.currentOrder.customerId = customer.autoincrementedId;
this.currentOrder.customerDescription = customer.description;
}
That is work. I can select Customer
from the list and it fill two filed in my currentOrder
object.
But when I load page my select control is empty even if the I have filled customerId
and customerDescription
in my Order
. I understand that the reason is that customer
is empty, but I don't know what is the best way to fix it.
How can I fill the select
when I am opening page ?
Upvotes: 0
Views: 33
Reputation: 104795
Use the value as text for obj in arr
syntax of ngOptions
- then set the ngModel
to the value
:
select(ng-model="customer"
ng-options="customer.autoincrementedId as customer.description for customer in vm.customers"
ng-change="vm.setCustomer(customer)")
And set this.customer
to the autoincrementedId
of the customer you want default selected.
Upvotes: 2