angularjs - Filter in ng-options not working -
i have object maps ids objects. display list of these object , use filter, cannot work. specifically, i'm trying prevent object id 2 appearing in options here's i've got: http://jsfiddle.net/9d2za/
<div ng-app ng-controller="ctrl"> unfiltered: <select ng-model="selectedbidtype" ng-options="bidtype.id bidtype.label (bidtypeid, bidtype) in bidtypes"> </select> <br> filtered: <select ng-model="selectedbidtype" ng-options="bidtype.id bidtype.label (bidtypeid, bidtype) in bidtypes | filter:{id: '!2'}"> </select> </div>
please note: cannot change structure of bidtypes
object in whatever fix come with. here's angularjs:
function ctrl($scope) { $scope.selectedbidtype = 1; // bid type objects indexed id fast lookup (this cannot changed in solution) $scope.bidtypes = { 1: {id: 1, label: "buy"}, 2: {id: 2, label: "sell"}, 3: {id: 3, label: "missing"} }; }
as described documentation, filter
filter accepts array first parameter, not object. in such cases, use custom filter make transformation:
mymodule.filter( 'objecttoarray', [ function () { return function (object) { var array = []; angular.foreach(object, function (element) { array.push(element); }); return array; }; } ] ) ;
and then, in template:
<select ng-options="… in bidtypes | objecttoarray | filter:{id:'!2'}">
Comments
Post a Comment