I have a list of values that are to be displayed as Radio buttons. Each radio button has a value with certain count that will be decreased if the radio button is selected. If radioButton1 is selected then the count becomes 1, if some other radio button say radioButton2 in this list is selected then the count of the radioButton1 is restored to its original value and the count for the radionButton2 is decreased by one. I have been trying to find a solution to this but haven't been able to. Any help will be greatly appreciated thanks!
app.component.ts
this.itemList = [
{ name: 'item1', count: 1},
{ name: 'item2', count: 2},
{ name: 'item3', count: 3},
{ name: 'item4', count: 2},
{ name: 'item5', count: 1},
]
onRadioSelect(userSelect){
this.itemList.forEach((selected,index)=>{
if(selected.name === userSelect.value){
selected.count -= 1;
if(selected.count === 0){
this.countZeroDisable= index;
}
}
app.component.html
<div *ngFor="let items of itemList; let idx = index" [ngClass]="{'disable': idx===countZeroDisable}">
<input type="radio" name="List1" [value]="items.name" [disabled]="idx===countZeroDisable" (change)= onRadioSelect(List1) #List1>
{{items.name}}({{items.count}})
</div>