Math functions in AngularJS bindings

ricick

Is there a way to use math functions in AngularJS bindings?

e.g.

<p>The percentage is {{Math.round(100*count/total)}}%</p>

This fiddle shows the problem

http://jsfiddle.net/ricick/jtA99/1/

Tosh

You have to inject Math into your scope, if you need to use it as $scope know nothing about Math.

Simplest way, you can do

$scope.Math = window.Math;

in your controller. Angular way to do this correctly would be create a Math service, I guess.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related