I am generating multiple checkboxes dynamically using ngFor. But here i need to enable one checkbox at a time, if one is checked the other checkboxes needs to be disabled.Similarly if i uncheck the checkbox other checkboxes needs to be enabled. How to acheive this in angular2?
<div class="col-12 mb-2" *ngFor="let option of question.options; let i = index;">
<input type="checkbox" [(ngModel)]="question.options[i].correct" [disabled]="!question.options[i].correct && i != activeIndex" (ngModelChange)="copyQuestionmarks(i)">
</div>
In the above code i am disabling the checkbox if its not a correct option and if that is not the active index. This works only for the first time, Suppose if i uncheck this other checkboxes won't get enabled.
Below is my ts code
public copyQuestionmarks(i : number){
this.activeIndex = i
}
Help appreciated!
Aucun commentaire:
Enregistrer un commentaire