Romain
Romain

Reputation: 3673

AngularJS: Filter ng-options not having specific values

I want to filter on a select like so :

<select ng-model="test" ng-options="c as c.label group by c.type for c in columns
| filter:{c.type:'!field'} | filter:{c.type:'!map'}"></select>

EDIT : Adding the column model :

Columns = [
{
    name: "name",
    label: "Label",
    info: "Information displayed in help",
    type: "type",
    view: "html template",
    style: "min-width: 10em;",
    show: true
},
{
 ...
}
];

Columns is used for several things and to optimize my code I need it to be also in a Select, but without the entries whose type are 'field' nor 'map'

Yet, I get to choose from everything, even the entries which types are 'field' and 'map'. Is there a clean way to do it ?

Upvotes: 31

Views: 68453

Answers (1)

AlwaysALearner
AlwaysALearner

Reputation: 43947

AngularJS NOT Filter

<select ng-model="test" ng-options="c as c.label group by c.type for c in columns
    | filter:{ type : '!field' }
    | filter:{ type : '!map' }">
</select>

Fiddle

From the docs:

"...The predicate can be negated by prefixing the string with !."

"A pattern object can be used to filter specific properties on objects contained by array. For example {name:"M", phone:"1"} predicate will return an array of items which have property name containing "M" and property phone containing "1"..."

Upvotes: 71

Related Questions