简体   繁体   English

Angularjs:如何在使用ng-option时在select中包含空选项

[英]Angularjs: How to include empty option in select when using ng-option

How can I add empty option in the beginning when I use ng-option to provide predefined list of options which doesn't include empty one? 当我使用ng-option提供不包含空选项的预定义选项列表时,如何在开头添加空选项?

An example in jade 玉中的一个例子

select(ng-model="property.Value", ng-options="item.Value as item.Name for item in property.Choices")

Just add an option with empty value inside of the select. 只需在select中添加一个空值的选项。

select(ng-model="property.Value", ng-options="item.Value as item.Name for item in property.Choices")
  option(value="")

Here's an example - http://jsfiddle.net/sseletskyy/uky9m/1/ 这是一个例子 - http://jsfiddle.net/sseletskyy/uky9m/1/

just modify the property.choices array in angular. 只需在angular中修改property.choices数组。

$scope.property.Choices.splice(0, 0, {"id":"0","Name":"Richard"}); $ scope.property.Choices.splice(0,0,{“id”:“0”,“Name”:“Richard”});

This just worked for me by modifying the object 这只是通过修改对象为我工作

angular.extend({'Please Select' : ''},objectName) angular.extend({'请选择':''},objectName)

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

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