0
試圖找出爲什麼我的上一個輸入不會更新。如何讓AngularJS更新輸入值?
這裏是我的JSFiddle
https://jsfiddle.net/Lzcvukq8/
我覺得有什麼毛病我的JS
function calculatorController($scope){
\t // Sixteen oz
\t $scope.costPerCanSixteen = function(){
\t \t return $scope.priceSixteen/(24*$scope.casesSixteen);
\t };
};
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<div id="sixteen-oz" ng-controller="calculatorController">
<div class='hr'></div>
<h1>One</h1>
<form class="form-horizontal">
<div class="form-group">
<label for="inputCases" class="col-sm-6 control-label">Amount of Cases</label>
<div class="col-sm-offset-1 col-sm-5">
<input type="number" min="0.01" step="0.01" max="2500" class="form-control" ng-model="casesSixteen"/>
</div>
</div>
<div class="form-group">
<label for="inputCost" class="col-sm-6 control-label">Cost Per Case</label>
<div class="col-sm-offset-1 col-sm-5">
<input type="number" min="0.01" step="0.01" max="2500" class="form-control" placeholder="29.40" ng-model="priceSixteen"/>
</div>
</div>
<div class="form-group">
<label for="canCost" class="col-sm-6 control-label">Cost Per Can</label>
<div class="col-sm-offset-1 col-sm-5">
<input type="text" class="form-control answer-to-input" value="{{ costPerCanSixteen() }}"/>
</div>
</div>
</form>
</div>
問題不在您發佈在問題主體中的代碼中。問題在於你在HTML中聲明瞭輸入。你不能在'value'標籤中放置一個表達式,從這樣的表達式調用一個函數並不是一個好習慣。 – Claies