I'm facing issue with my app. I'm trying to create a list of checkboxes, when the checkbox is clicked the value should be true and when clicked again the value should be false. Simple.
Here is my html
<li *ngFor="let checkbox of checkboxSelect">
<div class="checkbox-style">
<input type="checkbox" name ="{{checkbox.inputName}}"
[checked]="checkbox.name"
(change)="checkbox.name= !checkbox.name"/>
<div class="state">
<label>{{checkbox.label}}</label>
</div>
</div>
</li>
Here is my component.ts
showFirstName = true;
showLastName = true;
checkboxSelect: any[] = [{
label: 'First name',
name: this.showFirstName,
inputName: 'showFirstName'
}, {
label: 'Last name',
name: this.showLastName,
inputName: 'showLastName'
},
];
Everything is working except my 'name' value doesn't change to true/false when clicked.
On the other hand when I put that straight to html without *ngFor it's working
<li>
<div class="checkbox-style">
<input type="checkbox" name = "firstName"
[checked]="showFirstName"
(change)="showFirstName = !showFirstName"/>
<div class="state">
<label>First Name</label>
</div>
</div>
</li>
I wasn't so clear, my goal is to display divs depend on true/false
<div *ngIf="showFirstName" scope="col">First name</div>
<div *ngIf="showLastName" scope="col">Second name</div>
But it doesn't change at all.
Does anyone have an idea what's wrong with my code?