Using ngRepeat does not look right. It should be "item in items", and not vice versa. In addition, you do not use ng-model on your inputs, which makes it difficult to get an account.
So, if you add an ng model, you can get the score in different ways, one of which is:
app.controller('AppController', [ '$scope', function($scope) { $scope.items = [ {id: 1, title: "Can't Hold Us"}, {id: 2, title: "Just Give Me A Reason"}, {id: 3, title: "Mirrors"}, {id: 4, title: "Get Lucky"}, ]; $scope.selectedItems = 0; $scope.$watch('items', function(items){ var selectedItems = 0; angular.forEach(items, function(item){ selectedItems += item.selected ? 1 : 0; }) $scope.selectedItems = selectedItems; }, true); } ] );
<body ng-controller="AppController"> <ul> <li ng-repeat="item in items"> <label> <input type="checkbox" name="payment_id[]" ng-model="item.selected" /> {{item.title}} </label> </li> </ul> <div>Selected Items Length: {{selectedItems}}</div> </body>
Stewie
source share