Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get checked status on click event in angular Material

I have a angular 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) is doing some other task and I want the status of checkbox(either checked or unchecked) on click event.

I already tried looking over the object created by click and it does not have click object inside, so how can I detect if the checkbox is checked or not.

like image 681
Apoorv Avatar asked Oct 16 '17 07:10

Apoorv


People also ask

How do you check whether a checkbox is checked or not in angular?

The ng-checked Directive in AngularJS is used to read the checked or unchecked state of the checkbox or radio button to true or false. If the expression inside the ng-checked attribute returns true then the checkbox/radio button will be checked otherwise it will be unchecked.

How do you check checkbox is checked or not in angular 8?

Just define an ng-model directive in the checkbox and to find checkbox checked or not check model return value (TRUE or FALSE). If it has TRUE means checkbox is been checked.

What is indeterminate in Mat checkbox?

<mat-checkbox> supports an indeterminate state, similar to the native <input type="checkbox"> . While the indeterminate property of the checkbox is true, it will render as indeterminate regardless of the checked value. Any interaction with the checkbox by a user (i.e., clicking) will remove the indeterminate state.


1 Answers

You can use

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

or

(change)="showOptions($event);makeJSON($event.checked,i,j,k)"> 
like image 181
Günter Zöchbauer Avatar answered Sep 23 '22 18:09

Günter Zöchbauer