In my contrller.js I have array 'arr'
Like This :
$scope.arr = [
{block: 0},
{block: 1},
{block: 1},
]
I want to count items with block : 1 but not using ng-repeat?
I tried:
{{arr.lenght | filter:block == '1'}}
This is an example using filter
Html
<div ng-controller="MyCtrl">
Amount is {{(arr|amount)}}
</div>
Javascript
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.arr = [
{block: 0},
{block: 1},
{block: 1},
]
}
myApp.filter("amount", function(){
return function(array){
var amount = 0;
for(var i = 0; i < array.length; i++){
if(array[i].block == 1)
amount+= 1;
}
return amount;
};
});
Here a jsFiddle of the example
lengthwrong