【发布时间】:2015-05-30 23:58:15
【问题描述】:
我正在过滤我的 ng-options 这是我在我的 html 中的代码
<select class="form-control" id="selectType" ng-model="user.type" ng-init="user.type= types[0]">
<option ng-repeat="type in types" value="{{type}}">{{type}}</option>
</select>
<select class="form-control" ng-model="user.fullname" ng-options="employee as fullName(employee) for employee in employees | filter: user.type">
然后在我的控制器中我有这段代码
$scope.types = ['admin','encoder','checker','cashier'];
var getEmployees = function () {
$http.get(httpHost + '/employees').success( function (data) {
if(data.length !== 0){
$scope.employees = $scope.sortData(data,'emp_fname');
$scope.user.fullname = $scope.employees[0];
console.log("Employees:");
console.log($scope.employees);
}else{
$scope.noEmployees = true;
}
}).error(function (err) {
console.log(err);
});
};
getEmployees();
它会正确过滤它,但在下拉列表的第一项中留空 我的结果是这样的http://jsfiddle.net/sheppe/EeL9y/
【问题讨论】:
-
你从哪里得到
employees?它是如何填充的?它在原始形式中是什么样的(即其中有哪些项目)? -
我编辑了这个问题:D
-
我非常怀疑它与 Angular、AFAIU 有任何关系,这只是
<select>的行为。之前已经问过了:stackoverflow.com/questions/12654631/…
标签: angularjs ng-options