Math functions in AngularJS bindings

后端 未结 13 1198
无人及你
无人及你 2020-11-29 17:55

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

e.g.

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

13条回答
  •  我在风中等你
    2020-11-29 18:38

    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.

提交回复
热议问题