I am trying to do something like :
<div ng-controller="TestCtrl">
<div ng-repeat="(k,v) in items | filter:hasSecurityId">
{{k}} {{v.pos}}
</div>
</div>
AngularJs Part:
function TestCtrl($scope)
{
$scope.items = {
'A2F0C7':{'secId':'12345', 'pos':'a20'},
'C8B3D1':{'pos':'b10'}
};
$scope.hasSecurityId = function(k,v)
{
return v.hasOwnProperty('secId');
}
}
But somehow, it is showing me all items. How can I filter on (key,value) ?
Angular filters can only be applied to arrays and not objects, from angular's API -
You have two options here:
1) move
$scope.items
to an array or -2) pre-filter the
ng-repeat
items, like this:And on the Controller:
jsfiddle: http://jsfiddle.net/bmleite/WA2BE/
You can simply use angular.filter module, and then you can filter even by nested properties.
see: jsbin
2 Examples:
JS:
HTML:
I made a bit more of a generic filter that I've used in multiple projects already:
HTML:
JS:
Also you can use
ng-repeat
withng-if
:My solution would be create custom filter and use it:
And in html:
It is kind of late, but I looked for e similar filter and ended using something like this: