POV
POV

Reputation: 12005

How to uncheck checkbox immediately?

I have this HTML code:

<tr *ngFor="let stud of [1,2,3]">
    <mat-checkbox (change)="setPupilAbsence($event)"></mat-checkbox>
</tr>

And handler:

public setPupilAbsence(event: MatCheckbox): void {
      event.checked = false;
}

Upvotes: 1

Views: 378

Answers (1)

Silvermind
Silvermind

Reputation: 5944

The event.checked property is probably immutable or only there for read purposes. Also, the event is not the MatCheckbox itself, but it is MatCheckboxChange.

You can use the source of the event: event.source.checked = false;

import {MatCheckboxChange} from '@angular/material';
...
setPupilAbsence(event: MatCheckboxChange) {
    event.source.checked = false;
}

Stackblitz example

Upvotes: 3

Related Questions