The .ts file
export class ClassComponent implements OnInit {
est = true;
barca = false;
real = false;
constructor() {}
ngOnInit(): void {}
changeVal(inp: any) {
switch (inp) {
case 'barca':
this.est = false;
this.barca = true;
this.real = false;
break;
case 'real':
this.est = false;
this.barca = false;
this.real = true;
break;
case 'est':
this.est = true;
this.barca = false;
this.real = false;
break;
default:
break;
}
}
}
The .html file
<p [ngClass]="{'est': est, 'barca': barca, 'real': real}">class works!</p>
<input type="radio" name="class" (click)="changeVal('est')">est <br>
<input type="radio" name="class" (click)="changeVal('barca')">barca<br>
<input type="radio" name="class" (click)="changeVal('real')">real<br>
My intention is that, everytime someone click on the radio button barca, the barca value change to true and the others false, and so on for the others it works but I want to know if there is a better way to make it