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

Multiple ng-options set default option select not working

本文关键字:选择 工作 选项 默认 ng-options 设置 多个      更新时间:2023-09-26

我在Angular的select中遇到了一个选择默认值的问题。如果我的选择选项只有一个值,它' ok '和工作良好

<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>                          

这。