簡體   English   中英

多個ng-options設置默認選項選擇不起作用

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

我在選擇Angular時選擇默認值時遇到問題。 如果我選擇的選項只有一個值,就可以正常工作

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

在我的角度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>                          

而已。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM