1

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?

1
  • 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, in your view: {{amount}} prints 5. Commented Feb 27, 2017 at 15:12

3 Answers 3

3

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}}
Sign up to request clarification or add additional context in comments.

1 Comment

That did it. Thanks!
0

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

2 Comments

Hi Mehul, I tried this <div class="h3">{{item.cost * 0.(100 - item.discount)}}</div>, but it doesn't work. Here is my ng-repeat: ng-repeat="item in results"
@cnak2 what do you get in console?
0

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

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

1 Comment

Thanks, Ashish. That was just an example. I'm not actually using the this keyword. The actual line is: <div class="h3">{{item.cost * 0.(100 - item.discount)}}</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.