0

I have a checkbox that is updated from the model, but then the model is not updated clicking the checkbox.

Within a form I have:

<input type="checkbox"  ng-model="acceptEula"> I have read the EULA and I agree
<button type="submit" ng-click="pay()" translate>Proceed to Pay</button>
{{acceptEula}}

Clicking the checkbox, I can see how {{acceptEula}} shows true or false, it works.

When I click the button, I put a breakdown in pay() function. $scope.acceptEula is always false. What could be the problem?

Dabiel Kabuto
  • 2,762
  • 4
  • 29
  • 45
  • 1
    How confident are you that there's no scoping issues going on? I'd make sure that you declare `$scope.acceptEula = false` in your controller so that inheritance works properly. Even better would be `$scope.formData.acceptEula = false`. – Dylan Watt Mar 12 '15 at 20:30
  • Yes, in the controller I have $scope.acceptEula = false. In fact, if I change it to $scope.acceptEula = true; then the checkbox is checked and $scope.acceptEula is true in the debugger. The thing is that I have the same problem, I check off the control, but then the debugger continues giving me true. – Dabiel Kabuto Mar 12 '15 at 20:38
  • @DabielKabuto please see here http://jsbin.com/wonuyuzege/1/edit seems to working fine – sylwester Mar 12 '15 at 20:48

1 Answers1

0

Sorry, the question was not detailed in order to simplify the problem. In reality, I used "ng-switch" in the form. Finally I have found the problem: "This is a scope inheritance problem due to ng-switch creating it's own scope.". It is well explained at angularjs - ng-switch does not bind ng-model

The solution is to use dot in the model, for example $scope.form.acceptEula

Community
  • 1
  • 1
Dabiel Kabuto
  • 2,762
  • 4
  • 29
  • 45