I am trying to do a simple To Do list using Angular 2. I want to know which checkbox the user has clicked. And based on the click, i want to strikeout the text. I guess we could use :checked css property. But how do I implement this only through angular.
This is what i have done till now.
HTML:
<label *ngIf="isActivityEmpty()">No Activities to track! Start by adding one</label>
<ol *ngIf="!isActivityEmpty()">
<div *ngFor="let activity of activityList" >
<input class="left" name="{{activity}}" type="checkbox" [(ngModel)]="chkbox"/>
<li class="checked-{{chkbox}}">{{activity}}</li>
</div>
</ol>
Component:
export class AppComponent {
activity: string = '';
activityList: string[] = ['Sign up for play','Start Playing'];
chkbox: boolean = false;
constructor() {
}
addActivity(){
this.activityList.push(this.activity);
}
clearActivity(){
this.activityList.length = 0;
}
isActivityEmpty(){
let empty;
if(this.activityList.length==0)
empty = true;
else
empty = false;
return empty;
}
}
Link to Plnkr -> https://plnkr.co/edit/iikSmd4eIwpbQDPoJFZu?p=preview
If i select any one checkbox, it selects all the checkboxes.
I am new with Angular 2, any help would be good.
Thanks.