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
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
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
Axel Advento
I suggest editing your answer to include the code itself and just linking to jsfiddle for demo/reference.
Wai Ha Lee
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.
Avinash
I have added my explanation. Thanks for suggestion.