Skip to content
Advertisement

How check check-box dynamically in click event using Angular.js/JavaScript

I need to check check-box when user will click on a button the check box will selected using Angular.js. My code is below:

<td>
<input type="checkbox" name="answer_{{$index}}_check" 
   ng-model="answer.check" 
   ng-checked="answerIsSelected($parent.$index, $index)" 
   ng-click="toggleAnswerSelected($parent.$index, $index)" 
   ng-disabled="isDisabled($parent.$index, $index)" 
   ng-true-value="true" 
   ng-false-value="false" 
   style="margin-left:10px;"
 /> 
 </td>
<input type="button" value="Edit" ng-click="getValue()">

When user will click on edit button the check-box should be selected. I am providing my code in this Plunkr. You can find there is store button and edit button. When user will select some value and check-box click on store button, I need to store all value. When user will click on edit button, the stored value will set on required row check-box.

Advertisement

Answer

In your case it is simply:

$scope.getValue = function(){
      $scope.days.forEach(function (day) {
        day.answers.forEach(function (answer) {
          answer.check = true;
        });
      });
  }

https://plnkr.co/edit/LXl01lnROyjLZXUtRllx?p=preview

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement