當我使用ng-option提供預定義的不包含空選項的選項列表時,如何在開始時添加空選項?Angularjs:如何在使用ng選項時在select中包含空選項
一個例子,玉
select(ng-model="property.Value", ng-options="item.Value as item.Name for item in property.Choices")
當我使用ng-option提供預定義的不包含空選項的選項列表時,如何在開始時添加空選項?Angularjs:如何在使用ng選項時在select中包含空選項
一個例子,玉
select(ng-model="property.Value", ng-options="item.Value as item.Name for item in property.Choices")
只是選擇的內空值增加一個選項。
select(ng-model="property.Value", ng-options="item.Value as item.Name for item in property.Choices")
option(value="")
下面是一個例子 - http://jsfiddle.net/sseletskyy/uky9m/1/
只需修改property.choices陣列中的角。
$ scope.property.Choices.splice(0,0,{「id」:「0」,「Name」:「Richard」});
這只是通過修改對象
angular.extend工作對我來說({ '請選擇': ''},對象名)
非常感謝您! – 2014-04-07 20:09:02
如果數據來自服務,例如該怎麼辦?除此之外,我通常會盡量避免控制器中特定於視圖的事物。如果在視圖中有辦法做到這一點,那將是非常棒的。也許使用指令? – fnx 2014-07-15 15:20:54
如果您選擇了一個選項,然後又想回到空白選項,則無法正常工作。 – dang 2016-05-10 18:52:21