Fallenreaper Fallenreaper - 7 months ago 45
AngularJS Question

adding a filter to my ng-options returns no set?

I have an object i properly iterate over:

<select ng-options="value.name for (key,value) in ctrl.userList"></select>

I wanted to add a filter on the object, such as:


which would only show users without any current assigned superior.

It seems that right now, it shows none, but should show 1. Is there something I am missing when applying a filter?

Full example I have been working with:

<select ng-options="value.name for (key,value) in ctrl.userList | filter: value.superior!=null"></select>

The sample i am iterating over is:

Var obj = {
0: {name:"test", superior:null},
1: {name:"test 2", superior:0}

Sample Angular Fiddle: http://jsfiddle.net/p4Lj11on/


As per angular doc, first argument to filter must be array. You are passing object. If userList is an array it will work properly(try this). You can solve this by using custom filter.

app.filter('myfilter', function() {
  return function(obj) {
    var result = {};
    for(key in obj) {
      if(obj[key].superior !== null)
       result[key] = obj[key];
    return result;