Last active
August 29, 2015 13:59
-
-
Save daver182/10977262 to your computer and use it in GitHub Desktop.
Simple filter in Angularjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--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