When I select an item from my radio button list, I want to change its appearance by altering the background-color, text color, or highlighting. Unfortunately, due to the use of an ngFor loop for rendering the items, I am unable to achieve this as desired. Currently, on click, all the items in the list change color from red to blue instead of just the selected one.
I attempted using li::selection in CSS but it did not yield the expected results.
<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;
}