I am facing an issue where I have 3 ng-models and I need to fetch calculated data from the first two into the third one using angularjs
I attempted a solution but it doesn't seem to work as expected
Below is the HTML code snippet:
var urlt = 'http://localhost/tripsheets';
app.factory('tripsheetFactory', function ($http) {
return {
getTripsheets: function () {
return $http.get(urlt + '/all');
},
addTripsheet: function (tripsheet) {
return $http.post(urlt, tripsheet );
},
deleteTripsheet: function (tripsheet) {
return $http.delete(urlt + '?id=' + tripsheet.id);
},
updateTripsheet: function (tripsheet) {
return $http.put(urlt + '?id=' + tripsheet.id, tripsheet);
}
};
});
app.controller('TripsheetCtrl', function ($scope, tripsheetFactory) {
$scope.tripsheets = [];
$scope.getTotalCalc = function () {
return $scope.tripsheets.cash * $scope.tripsheets.tax;
};
tripsheetFactory.getTripsheets().then(function(data){
$scope.tripsheets = data.data;
$scope.tripsheet = {
tripsheet_num: $scope.tripsheets.length +1,
cash:null,
tax:null,
total: $scope.getTotalCalc()
};
});
});