AngularJS绑定中的数学函数 [英] Math functions in AngularJS bindings
本文介绍了AngularJS绑定中的数学函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在AngularJS绑定中使用数学函数?
Is there a way to use math functions in AngularJS bindings?
例如
<p>The percentage is {{Math.round(100*count/total)}}%</p>
这个小提琴显示了问题
http://jsfiddle.net/ricick/jtA99/1/
推荐答案
如果需要将Math
注入范围,则必须将它
$scope
对数学一无所知.
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.
这篇关于AngularJS绑定中的数学函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文