我是Angular的全新品牌,請耐心等待。我正在計算一個主「總預算」值減去顯示的其他值的總和。如何使用AngularJS中的ng-repeat數據進行計算
我的index.html目前:
<table class="table">
<thead>
<tr>
<th>Destination</th>
<th>Total Budget</th>
<th>Hotel Cost</th>
<th>Airfare Cost</th>
<th>Miscellaneous</th>
<th>Budget Remaining</th>
<th> </th>
</tr>
</thead>
<tbody>
<tr>
<td><input class="form-control" ng-model="trip.destination"></td>
<td><input class="form-control" ng-model="trip.budget"></td>
<td><input class="form-control" ng-model="trip.lodgingCost"></td>
<td><input class="form-control" ng-model="trip.airfareCost"></td>
<td><input class="form-control" ng-model="trip.miscCost"></td>
<td><button class="btn btn-primary" ng-click="addTrip()">Add Trip</button></td>
<td><button class="btn btn-info" ng-click="update()">Update</button> <button class="btn btn-info" ng-click="deselect()">Clear</button></td>
</tr>
<tr ng-repeat="trip in trips">
<td>{{trip.destination}}</td>
<td>{{trip.budget}}</td>
<td>{{trip.lodgingCost}}</td>
<td>{{trip.airfareCost}}</td>
<td>{{trip.miscCost}}</td>
<td>{{ getRemaining() }}</td> <<!--here is where I run the calculation -->
</tr>
</tbody>
</table>
在我controller.js,我試過的一些事情的變化我已經在計算器如this,this發現,和this,但我大部分都是未定義的和NaN的,好像實際值沒有被正確讀取?
任何幫助將不勝感激。
顯示控制器與'getRemaining'功能 –
是getRemaining製作一個HTTP請求?如果它是頁面將加載undefine,因爲數據仍然由您的控制器中的http進程 – Nello
我沒有太多的,因爲沒有我已經嘗試過的工作,所以我一直在刪除代碼,當它不播放不錯。但是,這是我的最後一次嘗試:'$ scope.getRemaining = function(){ \t var remaining = $ scope.trip.budget - ($ scope.trip.airfareCost + $ scope.trip.lodgingCost + $ scope.trip。miscCost); \t return remaining; }' – tardisdriver