2014-06-30 48 views
0

我有一个关键字段应该被选入一个SELECT html元素。这个SELECT填充了一个ng-repeatAngular ng-repeat不会选择绑定值

我定义了两个SELECT查询,用NG重复,另用NG选项:

<div ng-controller="MyDisplayCtrl"> 
    <select ng-model="context.id1"> 
     <option value="">-</option> 
     <option ng-repeat="i in lista" value="{{i.id}}">{{i.value}}</option> 
    </select> Should have "three" selected, but shows - <br/> 

    <select ng-model="context.id2" ng-options="i.value for i in lista"> 
    </select> Selects "three" automatically <br/> 
</div> 

我的控制器是这样的:

function MyDisplayCtrl($scope) { 
    var x1 = {id: 1, value: 'one'}; 
    var x2 = {id: 2, value: 'two'}; 
    var x3 = {id: 3, value: 'three'}; 
    window.setTimeout(function() { 
     $scope.$apply(function() { 
      $scope.lista = [x1, x2, x3]; 
     }); 
    }, 2000); 

    $scope.context = {id1: 3, id2: x3}; 
} 

我有这个名单带到客户端由一个AJAX,所以我在这里使用了一个setTimeout()

ng-options的方法有效,但我不会有一个对象,唯一的关键。

在这个小提琴看看:http://jsfiddle.net/nCG2H/

问题:我试图理解为什么第一个SELECT是不行的,因为算法中我得到了它依赖于从Ajax响应时间工作。

回答

2

请使用NG-选择= “{{i.id}}”,而不是价值= “{{i.id}}” ......

+0

这里的更新小提琴:http://jsfiddle.net/fv25x / –