2

In my controller I have this member:

$scope.sameOptionsOnReturn = true;

and in my view:

<input type="checkbox"
       ng-model="sameOptionsOnReturn"
       ng-checked="sameOptionsOnReturn"
       ng-value="true"
       ng-change="setReturnOptions" />

But the input does not bind to the checkbox; it's always true. What is wrong?

Note: removing ng-value="true" doesn't make any difference.

3
  • 1
    Try removing ng-value="true". Commented Jun 28, 2016 at 12:34
  • @Tushar - didn't make any difference I'm afraid Commented Jun 28, 2016 at 13:09
  • Try this: <input type="checkbox" ng-model="sameOptionsOnReturn" ng-checked="sameOptionsOnReturn = !sameOptionsOnReturn" ng-change="setReturnOptions()" /> Commented Jun 28, 2016 at 14:22

2 Answers 2

2

Since it does work in the snippet below, I have to assume there's something wrong elsewhere in your code.

function SuperController($scope) {
	$scope.sameOptionsOnReturn = true;
}

angular.module('myApp', []);
angular
    .module('myApp')
    .controller('SuperController', SuperController)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="SuperController as s">
    <input type="checkbox"
       ng-model="sameOptionsOnReturn"
       ng-checked="sameOptionsOnReturn"
       ng-value="true"
       ng-change="setReturnOptions" />
    
    {{sameOptionsOnReturn}}
  </div>
</div>

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

Comments

0

ng-model works for your bindings . So you don`t need to put ng-value="true" which making your checkbox always checked .remove it from the input checkbox . ng-model value will make your checkbox checked or unchecked .

1 Comment

didn't make any difference I'm afraid

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.