2014-04-28 102 views
2

這裏是我的html代碼爲什麼選擇的項目沒有被填充

<select id="userGroups" name="userGroups" ng-model="userGroups" class="form-control"> 
    <option value="{{grp.groupId}}" ng-repeat="grp in groups">{{grp.groupName}}</option> 
</select> 

這裏是我的控制器

function MyController($scope, MYAPI) { 
    $scope.groups = MYAPI.GroupList.get(); 
} 

爲什麼沒有被popuplated選擇?

好吧,我已經改變了我的控制器填充視圖之前解決組列表,但它仍然沒有顯示

MYApp.controller('CreateUserController', ['$scope', 'groupList', function($scope, groupList) { 
    $scope.groups = groupList; 
    debugger; //here I can see groups has objects which I need to display 

}]); 

但仍下拉沒有加載...

+0

您可以發佈?你在'$ scope.groups' – Satpal

+0

它得到返回的承諾....我檢查通過將獲得()行後調試器......但一旦數據被加載完畢後應該自動更新$ scope.groups? – coure2011

+0

TypeError:undefined不是函數 – coure2011

回答

1

正如Martin所說,您需要使用ng-options。

這是應該的樣子:

<select id="userGroups" 
     name="userGroups" 
     ng-model="userGroups" 
     ng-options="grp.groupId as grp.groupName for grp in groups" 
     class="form-control"> 
</select> 
+0

THX解釋如何通過grp.groupId設定值和文本grp.groupName – coure2011

0

Accorting到AngularJS documentation of select你必須使用ng-options。此用例不受ng-repeat支持:

ngOptions provides an iterator facility for the <option> element which should be used instead of ngRepeat when you want the select model to be bound to a non-string value. This is because an option element can only be bound to string values at present.