javascript - Angular Simple filter on ng-Repeat (>5) -
i have simple angular form, i'd filter ng-repeat values>5 shown.
<body ng-controller="mainctrl"> <div ng-repeat="item in items | filter:value:>5??????/p> <p><input type=text ng-model="item.value"></p> </div> </body>
i can't determine syntax this. assuming it's built in filter.
reference:
app.controller('mainctrl', function($scope) { $scope.items = [ { value: 1 }, { value: 2 }, { value: 5}, { value: 7 } ];
there no filter built in this, nor there syntax can pass default filter.
you can either:
1. pass function default filter.
html:
<div ng-repeat="item in items | filter:filterfn">
js:
$scope.filterfn = function(item) { return item.value > 5; };
2. register own filter
html:
<div ng-repeat="item in items | greaterthan:5">
js:
app.filter('greaterthan', function() { return function(items, value) { var filtered = []; (var = 0; < items.length; i++) { if (items[i].value > value) filtered.push(items[i]); } return filtered; } });
Comments
Post a Comment