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 ?
In my opinion the correct way to set a default value is to simply pre-fill your ng-model property with the value selected from your ng-options , angular does the rest. Essentially when you define the $scope property your select will bind to assign it the default value from your data array.
In AngularJS, you can also inject the $filter service within the controller and can use it with the following syntax for filter. Syntax: $filter("filter")(array, expression, compare, propertyKey) function myCtrl($scope, $filter) { $scope. finalResult = $filter("filter")( $scope.
The indexOf() method searches the array for the specified item, and returns its position. And return -1 if the item is not found. If you want to search from end to start, use the lastIndexOf() method: var Color = ["blue", "black", "brown", "gold"]; var a = Color.
Introduction to AngularJS Custom Filter. In AngularJS filters are used to modify or update the data before rendering the data on view or UI. Filters are clubbed in expression or directives using pipe (|) symbol.
<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"..."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With