javascript - Angularjs modal acting weird with checkboxes -


i have angular app in plunker.

when click on button, opens modal dialog list of items. 2 of these items pre-checked based on condition in checkbox table input.

this function pushes , splices:

$scope.togglecheck = function (course) {     //debugger     var x = $scope.checkplanneddetails(course);     if ($scope.selectedcourses.indexof(course) === -1){         $scope.selectedcourses.push(course);         $scope.planned += 3;     } else {         $scope.selectedcourses.splice($scope.selectedcourses.indexof(course), 1);         $scope.planned -= 3;     }      $scope.getpercentage(); }; 

when course selected(checked) list, adds 3 $scope.planned , increases progress bar accordingly. reduces in same way when checkbox unchecked.

but functionality happens in reverse items already checked when modal dialog loads. code going wrong?

the problem you're trying hold state of checkboxes in attitional array. instead should use "ng-" directives (like ng-model, or ng-checked checkboxes)

http://plnkr.co/edit/nm9n2zdbzl7iubmcatjz?p=preview

here modification:

        $scope.togglecheck = function (course) {             //debugger                 if(course.checked){                     $scope.planned += 3;                 } else {                     $scope.planned -= 3;                 }                   $scope.getpercentage();         }; 

and i've changed "ng-clicked" "ng-changed", because first 1 triggered before actual change of value


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -