2014-03-07 29 views
2

我已经在ng-repeat内下拉,如下所示。Angularjs显示从ng-repeat值中选择的选项

<div ng-model="list in lists"> 
<div> 
    <select ng-model="pType" ng-options="c.name in projType"></select> 
    <option value="{{list.value}"></option> 
</div> 

我的控制器是

App.controller('pOverCtrl', function ($scope, pOverRepository, $location) { 
     $scope.lists = projOverRepository.query(); 

     $scope.projType = [ 
      { value: '0', name: 'None Selected' }, 
      { value: '1', name: 'Construction' }, 
      { value: '2', name: 'Maintenance' }, 
     ]; 
}) 

下拉被填充的罚款。但我的目标是,当执行ng-repeat时,它会自动显示来自列表作用域的值。 请让我知道如何解决这个问题。

回答

2

使用diretive ng-selected

<div ng-model="list in lists"> 
    <select ng-model="pType" ng-options="c.name in projType">      
     <option ng-selected="list.value == list.selected" value="{{list.value}"></option> 
    </select> 

</div> 

假设list.selected变量包含选项的值选择

+0

它没有工作。基本上我试图填充下拉比显示选择来自数据库的选项。 –