简体   繁体   English

多个ng-options设置默认选项选择不起作用

[英]Multiple ng-options set default option select not working

I´m having an issue with to select a default value on a select with Angular. 我在选择Angular时选择默认值时遇到问题。 If my select options only has one value it´s ok and works fine 如果我选择的选项只有一个值,就可以正常工作

<select id="customerId"
        ng-model="customer"
        ng-options="customer.id  for customer in customersSelect">
</select>

In my angular js: 在我的角度js中:

 $scope.customer = customer;

But if I try with multiple elements on ng-options and I set the default option, is not working 但是,如果我尝试对ng-options使用多个元素,并且设置了默认选项,则无法正常工作

<select id="customerId"
        ng-model="customer"
        ng-options="customer.id as customer.name for customer in customersSelect">
</select>

Any ideas? 有任何想法吗?

You can use a option tag.like below: 您可以使用一个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>                          

Thats it. 而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM