1

I have a checkbox with ng-model assigned to it, and customized ng-true-value and ng-false-value. Is there ng-something to check that check box is checked? Also I tried using ng-checked but according to https://docs.angularjs.org/api/ng/directive/ngChecked ng-model and ng-checked should not be used together.

4 Answers 4

1

You just assign ng-model in simple input tag having type='checkbox' like

<input type="checkbox" id="your_property" ng-model="your_property" />

You will receive true and false in 'your_property'. No need of used ng-checked.

Sign up to request clarification or add additional context in comments.

Comments

1

You don't need to use ng-checked, ng-model is enough because it can give you false and true (if checked).

<!doctype html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Checkbox</title>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-beta.0/angular.min.js"></script>
</head>

<body ng-app="">
  <label>Checkbox demo:
    <input type="checkbox" ng-model="master">
  </label>
  <br/> My value is: {{master}}
</body>

</html>

Here is the plunker http://plnkr.co/edit/NaTBRCeq1BeqtinEbK2t?p=preview

Comments

0

maybe you are searching for ng-if ?! Include something like this in the plunker referenced on the angular page:

<span ng-if="master">Hello, I am checked.!</span>

'master' is the variable that is bound to the check-box of the input-element.

Comments

0
there is no need of ng-checked. ng-model will have the value to true or false. 
<div ng-app="">
      <input type="checkbox" ng-model="checked"/>
      {{checked}}
</div>

please check the example in http://jsfiddle.net/19v90cnv/

3 Comments

I suggest editing your answer to include the code itself and just linking to jsfiddle for demo/reference.
Also, going from a link-only answer to a code-only answer isn't that much better - I'd suggest making sure you explain whatever it is that your code is doing otherwise it's liable to be deleted.
I have added my explanation. Thanks for suggestion.

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.