I would like to change something (background-color, text color, highlight, etc.) on the item selected in my list of radio buttons when clicked/selected. The list is from an ngFor loop of items, which I think is why nothing is working. What I have now does change color, from red to blue, on click, but it changes all the items in the list, not the single item selected.
I've tried using li::selection in CSS, but that did not work.
<div class="container">
<div class="col-sm-12 form-group">
<p> <strong> Select Your Subject</strong></p>
<ng-container *ngFor="let subs of allSubjects">
<ul id="subList">
<li [ngClass]="{'blue' : toggle, 'red': !toggle}">
<label>
<input checked type="radio" name="ClassTimesSubjects"
[(ngModel)]="subs.classTimeSubjectsName"
[value]="subs.classTimeSubjectsName"
[(ngModel)]="ClassTimesSubjects" #ClassSubjects="ngModel" required
(click)="enableDisableRule()">
{{ subs.classTimeSubjectsName }}
<img [src]="subs.classTimeSubjectsImage" id="subPics">
</label>
</li>
</ul>
</ng-container>
</div>
</div>
Typescript...
toggle = true;
status = "Enable";
public allSubjects: Array<any>;
enableDisableRule(job) {
this.toggle = !this.toggle;
this.status = this.toggle ? "Enable" : "Disable";
}
CSS...
.blue {
background-color: blue;
}
.red {
background-color: red;
}