Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if any Checkbox is checked in Angular

Is there any function or ng-something to check if any of the displayed Checkboxes are checked?

I have the values through the ng-click="function()" and pass the values through. I can go by foot and check my array if any value is inside.

I want to activate/deactivate the "next"-button if any Checkbox is checked.

What's the easiest way?

like image 768
ohboy21 Avatar asked Jan 07 '14 09:01

ohboy21


People also ask

How do you check if 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 if a checkbox is checked or not in TypeScript?

To check if a checkbox element is checked in TypeScript: Type the element as HTMLInputElement using a type assertion. Use the checked property to see if the element is checked. The property will return true if it is checked and false otherwise.

How to get checked checkbox values in angular 13 apps?

Use the following steps to get checked checkbox values in angular 13 apps: First of all, open your terminal and execute the following command on it to install angular app: In this step, visit src/app directory and open app.module.ts file. Then add the following code into it:

How to check checkbox is checked or not in nG-model?

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.

How to check if checkbox is checked or not?

There are many ways to know weather a check box is checked or not you can use Reactive Form Control OR Template Driven Forms etc. But In your case I think you just want to check the checked property of a single checkbox then the easy way of doing that is to use template variable and access that in your ts file using View Child.

How to add a Master checkbox on top of checkbox list?

If you need to add one master checkbox on top and when you check that checkbox then bellow checkbox list check checked all and unchecked all. so same feature i will give you instruction how can be done this thing step by step. you can easily use with angular 6, angular 7, angular 8 and angular 9 app.


1 Answers

If you don't want to use a watcher, you can do something like this:

<input type='checkbox' ng-init='checkStatus=false' ng-model='checkStatus' ng-click='doIfChecked(checkStatus)'> 
like image 187
TOBlender Avatar answered Sep 21 '22 02:09

TOBlender