AngularJS Grouped选择不填充

时间:2014-04-08 11:28:33

标签: angularjs scope angularjs-scope

我在填充分组选择框时遇到问题 - 我无法将数据输入选择框。

我正在尝试按照http://docs.angularjs.org/api/ng/directive/select提供的以下示例:

  Color grouped by shade:
  <select ng-model="color" ng-options="c.name group by c.shade for c in colors">
  </select><br/>

app.js

var messageApp = angular.module('messageApp',
    ['ngRoute', 'messageControllers', 'ngResource', 'messageServices', 'contactServices']);

messageControllers.controller('MessageComposeCtrl', ['$scope', '$routeParams', 'Contact',
    function ($scope, $routeParams, Contact) {
        $scope.folder = 'Compose new message';

        $scope.contacts = Contact.query();
}]);

var contactServices = angular.module('contactServices', ['ngResource']);
contactServices.factory('Contact', ['$resource', function($resource) {
    return $resource('/api/v1/contacts/', {}, {
        query: { method: 'GET', isArray:false }
    });
}]);

我的观点

<h2><% folder %></h2>
<form role="form">
<div class="form-group">
<label for="to">Receiver *</label>
    <select ng-model="contacts" ng-options="c.name group by c.group for c in contacts">    
    </select>
</div>

输出

enter image description here

Baterang输出显示正在拉入联系人:

enter image description here

所以我的范围正确,因为<% folder %>正确填充。所以我在视图中的选择框的填充中出现了错误...

<select ng-model="contacts" ng-options="c.name group by c.group for c in contacts">    
</select>

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

联系人是一个对象,因此您需要使用对象数据源的理解表达式:

ng-options="c.name group by c.group for (key,c) in contacts"

请参阅select的角度文档。