我目前在控制台中收到错误消息:
Error: [ui.select:items] Expected an array but got '{}'.at select.min.js:7
at select.min.js:7
at $watchCollectionAction (angular.js:16527)
at Scope.$digest (angular.js:16664)
at Scope.$apply (angular.js:16928)
at done (angular.js:11266)
at completeRequest (angular.js:11464)
at XMLHttpRequest.requestLoaded (angular.js:11405)
我从已经在邮递员中检查的网络服务返回内容,该网络服务返回一个数组,80%的时间它不能填充下拉菜单和其他20%的我得到错误的时间但它仍然有效。
代码非常简单:
function selectCtrl($scope, $http) {
$scope.person = {};
$scope.option = {};
$scope.options = [];
var onUserComplete = function(response){
$scope.options = response.data;
console.log(response.data);
}
$http.get("http://localhost/api/user")
.then(onUserComplete);
}
HTML看起来像这样:
<ui-select ng-model="option.selected" theme="bootstrap" on-select="onSelectCallback($item)">
<ui-select-match placeholder="Select or search a person">{{$select.selected.username}}</ui-select-match>
<ui-select-choices repeat="item in options">
<div ng-bind-html="item.username | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
邮递员的数据如下所示:
[
{
"id": 1,
"username": "username1"
},
{
"id": 2,
"username": "username2"
}