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

标签 javascript angularjs ng-options

我在使用 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/

相关文章:

javascript - 查找 ng 重复中选择的选项

javascript - Angularjs(选择): Show other attribute from array than the one stored in ng-model

javascript - 如何将html字符串代码转换为将出现在前端的实际html工作代码?

javascript - 将 data-filter 属性添加到 wp_nav_menu

javascript - 单击时手动停止/跳过视频

javascript - Jasmine 监视 Angular 服务

javascript - AngularJS:如何使用 ngOption 从缓存的 Api 调用中迭代数据

javascript - 使用 .prependTo() 时奇怪的边距

javascript - 数据加载后动态生成 HTML

javascript - 仅在父元素内拖动指令?