Exploring the realm of mathematics within an angular expression, let's consider a scenario where a user can either have credit on the site or receive a percentage discount. Below is the code snippet in question:
<div ng-repeat="item in NewArrivals">
<div>{{item.NewPrice - userCredit | number:2}}</div>
<div>
The challenge at hand is to adjust the calculation based on whether the user is logged in or not. If the user is logged in, userCredit should be a set value. If not, userCredit should represent a 5% deduction from item.NewPrice.
These conditions are defined in the 'PageController.js' file:
if (TheUser == "notThere") {
console.log('5% discount for the user')
var userDiscount = 0.95;
} else {
var userCredit = 300;
}
How can we achieve the subtraction of 5% from newPrice for each item in the ng-repeat loop when the user is logged in, without duplicating the ng-repeat structure?