I'm using the modal from the Angular fork of Bootstrap 3: http://angular-ui.github.io/bootstrap/#/modal and I'm trying to use a checkbox inside the modal and get its value back in my main controller.
The checkbox value is well bound in the view but not in the controller of the modal. Here's an example of the problem: Plunker
The modal controller:
var ModalInstanceCtrl = function ($scope, $modalInstance) {
$scope.checked = false;
$scope.ok = function () {
$modalInstance.close( $scope.checked);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};
=> $scope.checked in the ok function doesn't contain the correct value...
The view:
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<label>
<input type="checkbox" ng-model="checked"> test
</label><br/>
Checked: {{checked}}
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>
Any idea?
Thanks by advance
$modalInstance.closewith a boolean works very well. If I put a String in there it works. No idea why.$modalInstance.close('Hi, I am a String');that works. See yarons, answer where he uses an object instead of a boolean. That's working around this exact problem.