cnak2 cnak2 -4 years ago 168
AngularJS Question

Calculation in angular expression

I have a situation where I return a dollar amount and a discount percentage from an API for a number of products. I have an ng-repeat, where nn the UI, I want to show a discounted amount.

Something like:

{{this.amount * .(100 - this.discount)}}


I tried this, but it doesn't work.

Any advice?

Answer Source

Are both this.amount and this.discount defined? The use of this here is strange, usually in angular you add variables you want to $scope.

E.g.

In your controller: $scope.amount = 5

Then your view: {{amount}} prints 5.


Ignoring this the use of the period before the brackets is causing your issue, try:

{{this.amount * (100 - this.discount) / 100}}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download