I'm making a list of questions (question's name and yes/no checkboxes)
The problem is that when I click on the second question checkboxes, it still changes the ones from first component.
Here's my code:
Rendering the list of questions:
<div *ngFor="let question of questions">
<app-question [question]="question"></app-question>
</div>
Each question:
<div class="question">
{{question}}
<div class="checkboxes">
<label class="checkbox-label">
<input class="checkbox" [(ngModel)]="checked.yes" (ngModelChange)="checkboxChanged('yes')" type="checkbox" id="check1"/>
<label for="check1" class="custom-checkbox"></label>
</label>
<label class="checkbox-label">
<input class="checkbox" [(ngModel)]="checked.no" (ngModelChange)="checkboxChanged('no')" type="checkbox" id="check2"/>
<label for="check2" class="custom-checkbox"></label>
</label>
</div>
</div>
checkboxChanged(value): void {
value === 'yes' ? this.checked["no"] = false : this.checked["yes"] = false;
}
Thanks
Edit: https://stackblitz.com/edit/angular-59bkvw
Solution: The problem was that my inputs and labels were sharing the same ids between components. I assigned an unique id like id="{{question}}" and it works. Thank you all for help.