Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Math.min() or Math.max() syntax in angular template?

Tags:

angular

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?

like image 403
Ping Woo Avatar asked May 14 '26 13:05

Ping Woo


1 Answers

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

like image 84
mast3rd3mon Avatar answered May 17 '26 04:05

mast3rd3mon