How to count how many boxes checked in Angular 2/4 using typescript. It should show the count of the check boxes checked, and if unchecked it should decrement to 0.
My example, data coming from server, which I loop through:
I know how to do it using foreach function in Angularjs, but cant understand how to do this in Typescript, generally I have to replace angular foreach method with Typescript foreach method? Need help
app.ts
data = [
{"name":"jason"},
{"name":"james"},
{"name":"josh"},
{"name":"joshua"}
];
calculateChecked = function() {
let count = 0;
angular.forEach(this.data, function(value) { //don't work in typescript
if(value.checked)
count++;
});
return count;
};
};
app.htm
<li class="list-group-item" *ngFor="let user of data">
<input type="checkbox" [ngModel]="user.checked"/>
{{user.name}}
</li>
<p>total checked: {{calculateChecked()}}</p>
should show:
And if unchecked should show 0
<div class="sasha-ui-list" #em *ngFor="let email of emails; let i=index"
(click)="onAddtoMessage(email)"> <div class="row"> <div class="col-lg-1">
<input class="magic-checkbox sasha_checkbox" name="emails" type="checkbox"
id="{{email.id}}" value="email" [checked]="checkboxFlag"> <label for="
{{email.id}}"></label> </div>
