Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a function with true value if checkbox is checked and function with false value when checkbox is unchecked

I have a simple checkbox input

<input type="checkbox" name="xxx" data-ng-clik='someFunction(true/false)' "/>

If user tick checkbox I want to call my someFunction(true) with true value and if user uncheck I want to call the same function someFunction(false) with false value.

Any suggetions how can I do that?

like image 605
sir_K Avatar asked May 12 '16 15:05

sir_K


1 Answers

You should call your method on ng-change of checkbox, to get correct changed value. Also add ng-model to get two way binding enable your checkbox value.

<input ng-model="myCheckbox" type="checkbox" name="xxx" 
       ng-change='someFunction(myCheckbox)'">
like image 157
Pankaj Parkar Avatar answered Oct 20 '22 00:10

Pankaj Parkar