¿Hay un evento para un grupo de radio mat en el que podamos detectar si cambia un valor? porque quiero activar un método o una función solo si el valor seleccionado de la radio cambia.
Entonces, por ejemplo, hago clic en el botón A y el valor es 0 y luego hago clic en el botón A nuevamente, entonces debería devolver falso ya que el valor no cambió.
#html
<mat-radio-group [(ngModel)]="filters" aria-label="Select an option" [disabled]="isLoading" > <mat-radio-button value="1" (change)="onChange($event)" > A </mat-radio-button> <mat-radio-button (change)="onChange($event)" value="2" > B </mat-radio-button> </mat-radio-group>#tscode
export class Something { filters: any; onChange(event: MatRadioChange) { console.log('event' , event) if (this.isLoading) { return; } this.table.pageIndex = 0; if (event.value === 2) { this.filters = '2'; this.callAllData(); } else { this.filters = '1'; this.callMyData(); } }Puede usar el enlace bidireccional [(ngModel)]="binding" para actualizar su variable como tal:
<mat-radio-group [(ngModel)]="selectedValue"> <mat-radio-button [value]="0">BUTTON A</mat-radio-button> <mat-radio-button [value]="1">BUTTON B</mat-radio-button> </mat-radio-group>En tu caso sería:
#html:
<mat-radio-group [(ngModel)]="filters" (change)="onChange()" aria-label="Select an option" [disabled]="isLoading" > <mat-radio-button value="1"> A </mat-radio-button> <mat-radio-button value="2"> B </mat-radio-button> </mat-radio-group>#mecanografiado:
export class Something { filters: any; onChange() { console.log('filters' , this.filters) if (this.isLoading) { return; } this.table.pageIndex = 0; if (this.filters === 2) { this.callAllData(); } else { this.callMyData(); } }