我有一个下拉列表,我使用ng-options
来加载控制器填充的模型中的值。现在我需要再添加一个<option value='any'>any</option>
选项,默认情况下该选项应该作为选定选项。如何以棱角分明的方式做到这一点?
<body ng-controller="myController">
<h1>States in India!</h1>
<select ng-options="state for state in states" ng-model="selectedState"> </select>
</body>
附加了Plnkr链接 - Plnkr link
答案 0 :(得分:1)
@Pradeep,使用
<select ng-options="state for state in states" ng-model="selectedState">
<option value="">-- choose state --</option>
</select>
答案 1 :(得分:0)
您只需在数组中添加一个项目并将其分配给$ scope.selected。 Plunkr
$scope.selectedState = "Select";
$scope.states=["Select","Karnataka", "Tamilnadu", "Andra-Pradesh", "Rajasthan"]
答案 2 :(得分:0)
在option
标记内写select
标记,如
<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"]
})
我在plunker中运行它的工作请尝试这个