[英]adding a default option when using ng-options in Angularjs
I m having a dropdown for which I am using the ng-options
to load the values from the model which is populated by the controller. 我正在使用
ng-options
下拉列表,以从控制器填充的模型中加载值。 Now I need to have one more option which is <option value='any'>any</option>
which should be there as the selected option by default. 现在,我需要再有一个选项,它是
<option value='any'>any</option>
,默认情况下该选项应作为所选选项存在。 How to do this in angular way? 如何以角度的方式做到这一点?
<body ng-controller="myController">
<h1>States in India!</h1>
<select ng-options="state for state in states" ng-model="selectedState"> </select>
</body>
Plnkr link attached - Plnkr link 附加了Plnkr链接-Plnkr链接
@Pradeep, use @Pradeep,使用
<select ng-options="state for state in states" ng-model="selectedState">
<option value="">-- choose state --</option>
</select>
write option
tag inside the select
tag like 在
select
标签内写入option
标签,例如
<body ng-controller="myController">
<h1>States in India!</h1>
<select ng-options="state as state for state in states" ng-model="selectedState">
<option value=''>any</option>
</select>
</body>
angular.module("myApp", []).
controller("myController", function($scope){
$scope.states=["Karnataka", "Tamilnadu", "Andra-Pradesh", "Rajasthan"]
})
I have run in plunker its work please try this 我已经在工作中尝试了,请尝试一下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.