개발
[angularjs] filter된 array 사이즈 알아내기
세모리a
2015. 2. 27. 22:06
아래와 같이 array를 filter할 경우 그 length를 가져오는 예제이다
filter한 내용을 새로 변수를 선언해서 넣어주는게 포인트이다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <div ng-app="myApp"> <div ng-controller="MyCtrl"> Filter: <input ng-model='filterExpr'> <button ng-click='items.push("car")'>Add sth to the list</button> <button ng-click='items.splice(items.length-1,1)'>minus sth from the list</button> <hr> <ul> <li ng-repeat='item in filtered = (items | filter:filterExpr) track by $index'>{{item}}</li> </ul> <hr> Filtered list has {{filtered.length}} items </div> </div> <script type="text/javascript"> <!-- angular.module('myApp', []) .controller('MyCtrl', function ($scope) { $scope.items = ['foo', 'bar', 'foobar']; }); //--> </script> | cs |
데모
See the Pen angularjs filter length by homin ahn (@beans9) on CodePen.
// 필터된 데이터 길이 구하기