Set checkboxes as checked using angularjs
31,131
Use ng-checked
for check-boxes,
<label class="radio-inline">
<input type="checkbox" ng-model="newItem.have_voter_id" value="have_voter_id" ng-checked="newItem.have_voter_id=='Y'"/><?php echo $this->lang->line('label_voter_id'); ?>
</label>
<label class="radio-inline">
<input type="checkbox" ng-model="newItem.have_passport" value="passport" ng-checked="newItem.have_passport=='Y'"/> <?php echo $this->lang->line('label_passport'); ?>
</label>
![Nisham Mahsin](https://i.stack.imgur.com/JTykt.jpg?s=256&g=1)
Author by
Nisham Mahsin
I like finding and solving problems with computers. My passion for programming is in my ability to make tools that make people's lives easier. I am just a hard worker and I spend all of my free time looking up stuff to make my job easier, learning how to make life more awesome or planning out my future.
Updated on July 09, 2022Comments
-
Nisham Mahsin almost 2 years
I have some checkboxes and their value is in database are 'Y' or 'N' as enum.for making updation i have to review all the checkboxes.how to view checkboxes as checked. this is code for checkboxes
<label class="radio-inline"> <input type="checkbox" ng-model="newItem.have_voter_id" value="have_voter_id" /><?php echo $this->lang->line('label_voter_id'); ?> </label> <label class="radio-inline"> <input type="checkbox" ng-model="newItem.have_passport" value="passport" /> <?php echo $this->lang->line('label_passport'); ?> </label>
and this is the function for view and updation
$scope.edit = function(id,family_id) { $scope.action = 'update'; FamilyMem.get({id:id,family_id:family_id}, function (response) { // success $scope.newItem = response.data; // store result to variable $("#myModal").modal('show'); }, function (error) { // ajax loading error Data.errorMsg(); // display error notification //$scope.edit = false; }); };
and edit button
<a href="" class="btn btn-magenta btn-sm" ng-click="edit(family_member.id,family_member.family_id)">