下面的代码片段是一个用于$modal.open()的控制器,不知道为什么ok函数不能获取数据绑定改变的最新数据。
myModule.controller('ModalCtrl', function($scope, $modalInstance) {
$scope.job = 'student'; // changed by html radio button, default is 'student'
// called by a button with ng-click="ok()" in modal view
$scope.ok = function() {
// no matter what job i changed, the $scope.job always is default value 'student'
$modalInstance.close({
selected_job : $scope.job
});
};
});
这是html片段
<script type="text/ng-template" id="sendToModal.html">
<div>
<div class="modal-header">
<h4>Job</h4>
</div>
<div class="modal-body">
<label class="radio-inline">
<input type="radio" name="jobOption"
data-ng-model="job"
data-ng-value="student">Student
</label>
<label class="radio-inline">
<input type="radio" name="jobOption"
data-ng-model="job"
data-ng-value="teachch">Teacher
</label>
<div class="modal-footer">
<button class="btn btn-primary" data-ng-click="ok()">Confirm</button>
<button class="btn btn-warning" data-ng-click="cancel()">Cancel</button>
</div>
</div>
</script>