Angular:ng-repeat中的ng-options

时间:2015-10-08 11:23:24

标签: angularjs ng-repeat ng-options

我有一个请求集合,每个请求都有状态集合。我正在尝试为每个请求创建一个下拉列表并填充其状态。如何读取每个请求的选定状态?

样品控制器是:

// Code goes here
var app = angular.module('demo', []);


app.controller('myController', function($scope){
$scope.requests=[{"name": "Request1", 
                  "statusList": [{ "name": "status1", "isSelected": true },
                                 { "name": "status2", "isSelected": false }
                                ]
                },{"name": "Request2", 
                   "statusList": [{ "name": "status3","isSelected": false },
                                 { "name": "status4", "isSelected": false }
                    ]
                }];

});

和示例html:

<div class="container" ng-controller="myController">
<div>

    <ul ng-repeat="request in requests">
      {{request.name}}
  <li>
    <select class="form-control" ng-options="status as status.name for status in request.statusList" ng-model="selectedStatus"></select>
  </li>
</ul>

  </div>
</div>

the plunker在这里:http://plnkr.co/edit/KkYgCDTWbWuorTOQISPo?p=preview

1 个答案:

答案 0 :(得分:1)

使用request实例

创建模型 像这样

ng-model="request.selectedStatus"

然后你可以从$scope.requests

阅读