cnak2
cnak2

Reputation: 1841

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?

Upvotes: 1

Views: 2773

Answers (3)

thodic
thodic

Reputation: 2259

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}}

Upvotes: 3

Ashish Santikari
Ashish Santikari

Reputation: 443

remove this keyword. Instead, use scope variables to calculate the value.

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

Upvotes: 0

mehulmpt
mehulmpt

Reputation: 16587

This is the valid syntax: {{amount * 0.(100 - discount)}} (notice that 0)

Upvotes: 0

Related Questions