I'm pretty brand new to Angular so please bear with me. I am trying to make a calculation of a main "total budget" value minus the sum of other values displayed.
My index.html is currently:
<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>
In my controller.js, I've tried variations of some of the things I have found on stackoverflow such as this, this, and this, but I've mostly been getting undefined and NaN's, as if the actual value isn't being read properly?
Any help would be greatly appreciated.
getRemainingfunction$scope.getRemaining = function(){ var remainder = $scope.trip.budget - ( $scope.trip.airfareCost + $scope.trip.lodgingCost + $scope.trip.miscCost); return remainder; }