2

In my app I have the following checkbox

<input class="js-rooms" 
       id="checkid" 
       ng-keypress="$event.keyCode == 13 && getItem(0)" 
       ng-click="getItem(0)" 
       type="checkbox"/>

When the input is clicked and checked then the function getItem(0) is called. However, when I click the checkbox again and uncheck it and re-submit then the same function gets fired, obviously.

What I would like to do(in the simplest way possible) is to fire off the function getItem(1) when the checkbox is clicked and fire off getItem(0) when the checkbox is NOT clicked. I am looking for the simplest solution possible. Any thoughts?

1 Answer 1

2

Add ng-model in your checkbox.

And for checkBox angular has ng-true-value && ng-false-value

Like this '

<input class="js-rooms" 
       ng-model="checkid" 
       ng-keypress="$event.keyCode == 13 && setRoom(checkid)" 
       ng-click="getItem(checkid)"  
       ng-true-value="1"
       ng-false-value="0" 
       type="checkbox"/>
Sign up to request clarification or add additional context in comments.

1 Comment

Great, elegant and simple! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.