我有一个像这样的对象列表:
$scope.list = [ { id : 1, value : "one"},
{ id : 2, value : "two"},
{ id : 3, value : "three"} ];
我希望它输出如下列表:
<select>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
执行此操作所需的ng-options语法是什么?
答案 0 :(得分:1)
你可以试试这个;
<select name="yourname" ng-options="option.id as option.value for option in list"></select>
答案 1 :(得分:1)
<强> HTML 强>
<div ng-controller = "fessCntrl">
<select ng-model="selectedItem" ng-options="selectedItem as selectedItem.value for selectedItem in list" ></select>
</div>
<强> JS 强>
$scope.list = [ { id : 1, value : "one"},
{ id : 2, value : "two"},
{ id : 3, value : "three"} ];
// select 1st by default
$scope.selectedItem = $scope.list[0];
演示 Fiddle