8

In my pagination component, here is my code below:

<p>Showing {{(page-1) * pageSize}} to {{ Math.min((page-1) * pageSize + pageSize,tasks.length)}} of {{tasks.length}}</p>. 

But it did not works. Can anybody tell what problem it has?

1
  • you will probably need to have a local function in your class which mocks the min and max functions. or you could try to instantiate Math as a local variable? Feb 26, 2019 at 16:25

2 Answers 2

8

In your component, you could add math = Math;, then in your html, change it to

<p>Showing {{(page-1) * pageSize}} to {{ math.min((page-1) * pageSize + pageSize, tasks.length)}} of {{tasks.length}}</p>.

This creates a local copy of Math without needing to create extra functions and getters

8

Check the original answer of Günter Zöchbauer

In short: It is not possible to access global variables from within the template files.

You have to at least create a getter that returns global variable.

In your typescript file create a getter called Math

get Math() {
  return Math;
}

BUT I would either rename it to math or create a helper methods in my typescript file

1
  • You are right, I define a customer method and works, but there is no inbuilt method like Math.min() in Typescript?
    – Ping Woo
    Feb 26, 2019 at 16:40

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.