My situation involves a dynamic variable assigned from a service, requiring a real-time calculator to update another variable using its value.
Below is the relevant code snippet:
$scope.getSubTotalSCTax = function(){
TableService.checkOut('SubTotal', $scope.DetailMeja.finCheckInID)
.then(function(response){
console.log(response);
$ionicLoading.hide();
$scope.checkOut = {
SubTotal: response.SubTotal,
TaxPercentage: response.TaxPercentage,
ServiceChargePercentage: response.SCPercentage,
};
}, function(err){
console.log(err);
})
};
$scope.getSubTotalSCTax();
$scope.checkOut.ServiceCharge = $scope.checkOut.SubTotal * $scope.checkOut.ServiceChargePercentage / 100;
$scope.checkOut.Tax = $scope.checkOut.SubTotal * $scope.checkOut.TaxPercentage / 100;
However, an error stating
TypeError: Cannot read property 'SubTotal' of undefined
occurs at the line $scope.checkOut.ServiceCharge = $scope.checkOut.SubTotal * $scope.checkOut.ServiceChargePercentage / 100;
*UPDATE :
I have included an input type="text"
for both Tax Percentage and Service Charge Percentage.
These values need to trigger a recalculation each time they are changed.
*UPDATE2 :
The recalculation issue has been resolved by utilizing the ng-change
event to call a function that runs the recalculate
process.