I am using the AngularJs ui bootstrap modal. I have a page with checkboxes. When the user checks on the checkboxes and click on a button, it passes the checked checkboxes to the modal:
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
resolve: {
checkedSearches: function () {
var checkedSearches = [];
angular.forEach($scope.searches, function(search)
{
if(search.checked) {
checkedSearches.push(search);
}
});
return checkedSearches;
}
}
});
In my modal, we redisplay the data as checkboxes again. The user can select/unselect the checkboxes and click save, and it will save all the selected checkboxes.
var ModalInstanceCtrl = function ($scope, $modalInstance, checkedSearches) {
$scope.checkedSearches = checkedSearches;
var saveSearches = [];
angular.forEach($scope.checkSearches, function(search)
{
if(search.checked) {
saveSearches.push(search);
}
});
}
Issue, is that, it is saving ALL the checkboxes. Seems as though the checked property stays with the checkboxes, even though the user unchecks it in the modal. I haven't include the code to save the searches. I basically pushed on to the searchSearches array, and it seems to be pushing all the checkboxes, including unchecked ones.
Here is my view/modal for the checkboxes:
<tr ng-repeat="search in checkedSearches">
<td><input type="checkbox" ng-checked="search.checked" name="search" ng-model="search.checked" /></td><td>{{search.id}}</td><td>{{search.name}}</td>
</tr>