Reputation: 3
i have a quick question. I have a filter where i pass an array and get back an Array:
The Filter returns a JSON Array generated by underscore.js library:
myApp.filter('theFilter', function () {
return function(items){
return _.countBy(items, function(num) {
return num % 2 == 0 ? 'even': 'odd';
});
};
});
this {{array | theFilter }}
outputs only a json array like this: {{ "even":3, "odd":5 }}
How can i output the value of even for example?
Thanks and best regards
Upvotes: 0
Views: 75
Reputation: 185
I think maybe you need write another filter:
myApp.filter('theFilter', function () {
return function(items){
return _.countBy(items, function(num) {
return num % 2 == 0 ? 'even': 'odd';
});
};
});
myApp.filter('attr', function () {
return function(obj, attrName){
return obj ? obj[attrName] : undefined;
};
});
{{array | theFilter | attr:'even'}}
Upvotes: 0
Reputation: 2053
myApp.filter('theFilter', function () {
return function(items){
return _.countBy(items, function(num) {
return num % 2 == 0 ? 'even': 'odd';
}).even;
};
});
Upvotes: 0