我的$ scope变量不会根据模态中输入字段中的值进行更新。在下面的代码中,$ scope.markup始终为0,即使我将输入字段更改为其他值也是如此。这段代码有什么问题?
打开模态:
$scope.openCalculator = function() {
$modal.open({
templateUrl: '/Scripts/templates/modalMarkupCalculator.html',
controller: 'modalMarkupCalculatorCtrl',
windowClass: 'modal-markup-calculator'
});
modalMarkupCalculator.html:
<div class="modal-header">
<h3 class="modal-title">Markup and Discount Calculator</h3>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-md-7 control-label">Markup %</label>
<div class="col-md-4">
<input type="number"
class="form-control"
ng-model="markup"
ng-change="markupChanged()"
ng-enabled="markupEditable" />
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="close()">Close</button>
</div>
modalMarkupCalculatorCtrl.js
myApp.controller('modalMarkupCalculatorCtrl', [
'$modalInstance', '$scope', function ($modalInstance, $scope) {
$scope.markup = 0;
$scope.markupChanged = function() {
// $scope.markup is always 0 here!! It should be what the input is changed to!
if (!$scope.markup) {
$scope.clientDiscountEditable = false;
} else {
$scope.clientDiscountEditable = true;
}
}
$scope.close = function () {
$modalInstance.dismiss('close');
};
}
]);