Count & Print The Checked Inputs With Angularjs
I used ng-repeat to print the list of input checkbox. How do I count and print the number of checked checkboxes? JavaScript var app = angular.module('plunker', []); app.controller
Solution 1:
JS:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.lists = [
{'id':'1', 'name':'list 1', checked: true},
{'id':'2', 'name':'list 2'},
{'id':'3', 'name':'Macbook Pro'},
{'id':'4', 'name':'Dell Optiplex 755'},
{'id':'5', 'name':'Google Nexus S'}
];
$scope.$watch('lists', function(lists){
$scope.count = 0;
angular.forEach(lists, function(list){
if(list.checked){
$scope.count += 1;
}
})
}, true);
});
VIEW:
<bodyng-controller="MainCtrl"><ulstyle="padding:10px;"><inputtype="text"ng-model="fil.name" /><ling-repeat="list in lists | filter:fil"><divstyle="margin-bottom:0;"class="checkbox"><label><inputtype="checkbox"name="list_id[]"ng-model="list.checked"value="{{list.id}}" />
{{list.name}}
</label></div></li></ul><strong>Count: {{count}}</strong></body>
Post a Comment for "Count & Print The Checked Inputs With Angularjs"