javascript - Angular ng-repeat math -
i want create math inside angular expression, following; user can have credit site or user gets percentage in discount. have following code:
<div ng-repeat="item in newarrivals"> <div>{{item.newprice - usercredit | number:2}}</div> <div> what want when user logged in usercredit becomes number, simple, or if user not logged in usercredit -5% of item.newprice, , there problem.
this have in 'pagecontroller.js'
if (theuser == "notthere") { console.log('5% discount user') var userdiscount = 0.95; } else { var usercredit = 300; } how able newprice minus 5% each item in ng-repeat if user logged in? without making 2 different ng-repeats.
this how can manage it
<div ng-repeat="item in newarrivals"> <div ng-if="userdiscount">{{item.newprice * userdiscount | number:2}}</div> <div ng-if="usercredit">{{item.newprice - usercredit | number:2}}</div> <div>
Comments
Post a Comment