ng-repeat

How to filter (key, value) with ng-repeat in AngularJs?

◇◆丶佛笑我妖孽 提交于 2019-11-26 00:58:59
问题 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) ? 回答1: Angular filters can only be applied to

How to filter (key, value) with ng-repeat in AngularJs?

纵饮孤独 提交于 2019-11-25 21:03:48
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) ? bmleite Angular filters can only be applied to arrays and not objects, from angular's API - "Selects a subset of items from array and returns it as a new array." You