AngularJS 绑定中的数学函数 [英] Math functions in AngularJS bindings

查看:18
本文介绍了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;

在您的控制器中.我猜,正确执行此操作的 Angular 方法是创建一个数学服务.

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

这篇关于AngularJS 绑定中的数学函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆