Get check status on click event in angular Material

I have a corner element

<mat-checkbox class="btn-block" 
              labelPosition="before" 
              (change)="showOptions($event)" 
              (click)="makeJSON($event.checked,i,j,k)">
</mat-checkbox>

Here onchange (which actually gives the status of checkout) performs some other task, and I want the status of checkbox (either checked or not) for the click event.

I have already tried to view the object created by a click, and there is no click object inside it, since I can determine if the checkbox is checked or not.

+19
source share
3 answers

you can use

(change)="showOptions($event)" 
(change)="makeJSON($event.checked,i,j,k)">

or

(change)="showOptions($event);makeJSON($event.checked,i,j,k)">
+36
source

Another solution may be, you can use the template link variable with a checkbox and pass this variable to the method parameter.

 <mat-checkbox #checkbox (change)='showOptions(checkbox.checked)' value=''>all</mat-checkbox> 

#checkbox , (, , ..). checkbox.checked true false.

+1
whTax =false;                  
<mat-checkbox color="primary"
                      name="whTax" [checked]="false"
                      [(ngModel)]="whTax" id="IsHold"
                      (change)="onWHChange(whTax)">
                        W/H TAX
                  </mat-checkbox>
    onWHChange(isWhChecked){
      console.log('isWhChecked:>>', isWhChecked);
    }
-1
source

Source: https://habr.com/ru/post/1687536/


All Articles