Skip to content

Instantly share code, notes, and snippets.

@daver182
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daver182/10977262 to your computer and use it in GitHub Desktop.
Save daver182/10977262 to your computer and use it in GitHub Desktop.
Simple filter in Angularjs
//First we create the filter, is very simple. When you get the input it has all the items from the ngRepeat directive, then you
//iterate all over the array in compare the value with something, if it's right you push it into an output array.
'use strict';
angular.module('appName').filter('filterName', function (Util, Events) {
return function (input) {
if(input && input.length > 0){
var out = [];
for (var i = 0; i < input.length; i++) {
var value = input[i].counter;
if(value > 100){
out.push(value)
}else if(value < 50){
out.push(value);
}
}
return out;
}
};
});
<!--How to use it-->
<item class="item" ng-repeat="item in items | filterName">
<h3>{{item.title}}</h3>
<h4>{{item.description}}</h4>
<p>{{item.counter}}</p>
</item>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment