AngularJS Checkbox not working


I have a class called Case that contains a list of executionSteps. Each executionStep has a boolean property called enabled. I am trying to set in on the HTML side but it never gets updated on the JS side.
HTML side

<input type="checkbox" 
  ng-model="aa" ng-change="updateCaseExecutionStep('{{}}','{{}}','{{acase.executionSteps[0].id}}','{{acase.executionSteps[0]}}')"/>

On the controller side I have the function
defined as shown below

$scope.updateCaseExecutionStep = function(studyId,caseId,executionStepId,executionStep){  

Problem is when I update my checkbox or even manually update the enabled property of the executionStep

$scope.updateCaseExecutionStep = function(studyId,caseId,executionStepId,executionStep){  
    executionStep.enabled = true;

I don’t see any change. The enabled property of executionStep passed in the JS does not change. Please help.

Do I have to modify somehow on the The HTML side ?


You are trying to force too complex solution. To start with, you do not need ng-checked nor ng-change when you are using ng-model.

Let’s say you have the following controller

app.controller('MainCtrl', function($scope) {
  $ = { 
    caseId: 0,
    steps: [
      { id: 1, name: 'First step', enabled: true }, 
      { id: 2, name: 'Second step', enabled: false },
      { id: 2, name: 'Third step', enabled: false }]

And related HTML

<div ng-repeat="step in case.steps">
  <input type="checkbox" ng-model="step.enabled">&nbsp;{{ }}

That’s all it takes!

Example Plunk here


If you need to do some processing based on selection, then yes, you could add ng-change to input control. Then HTML becomes

<input type="checkbox" ng-model="step.enabled" ng-change="stateChanged(step)">&nbsp;{{ }}

And in controller

$scope.stateChanged = function(step){
  console.log('Changed step id:' + + ' enabled state to ' + step.enabled;   

Answered By – Mikko Viitala

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published