Reputation: 3560
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.
Upvotes: 0
Views: 70
Reputation: 387
You need to Add getValue function in your controller.
var self = this;
self.getValue = function(){
$scope.isDisabled = function(dayIdx, answerIdx) {
console.log('isDisabled', $scope.selectedAnswers[dayIdx].chkbox);
return (!$scope.answerIsSelected(dayIdx, answerIdx)
&& $scope.selectedAnswers[dayIdx].chkbox.length === 2);
};
};
Upvotes: 0
Reputation: 2404
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
Upvotes: 1