0

I have a checkbox in my view

<input type="checkbox" ng-model="trackers[tracker._id].enable" ng-click="toggleTracker(tracker._id);"/>

And a function in my controller

$scope.toggleTracker = function(trackerId){
    $scope.trackers[trackerId].enable = !$scope.trackers[trackerId].enable;
    console.log($scope.trackers[trackerId].enable)
}

But each time I check the box the enable property does not change. What could be wrong with my code?

1
  • please show more code. also if you are using ng-model - you shouldn't need to have a click handler. Commented Sep 10, 2015 at 15:11

2 Answers 2

1

Since you have ng-model connected to the input it should change when you click. Then you also have the ng-click so it changes back to the first value.

Just remove the ng-click and your good.

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

Comments

1

You shouldn't use both ng-model and an ng-click function toggling the enable state. Maybe it overrides and negate the toggle because they are executed one after the other.

Just use the ng-model property and it should work.

Comments

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.