我在使用 Angular 选择默认值时遇到问题。 如果我选择的选项只有一个值,那就可以并且工作正常
<select id="customerId"
ng-model="customer"
ng-options="customer.id for customer in customersSelect">
</select>
在我的 Angular js中:
$scope.customer = customer;
但是,如果我尝试在 ng-options
上使用多个元素并设置默认选项,则不起作用
<select id="customerId"
ng-model="customer"
ng-options="customer.id as customer.name for customer in customersSelect">
</select>
有什么想法吗?
最佳答案
您可以使用option
标签。如下所示:
<select
id="customerId"
ng-model="customer"
ng-options="customer.id as customer.name for customer in customersSelect">
<option value="">PLease select one</option>
</select>
就是这样。
关于javascript - 多个 ng-options 设置默认选项选择不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33238200/