角双花括号内的函数调用 [英] function call inside Angular double curly braces

查看:180
本文介绍了角双花括号内的函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在Kendo UI中的热图的代码位.

This is my code bit of a heat-map in Kendo UI.

<div ng-repeat="h in row.hours" ng-style="h.styleStr" 
    data-value="{{params.compare ? h.percentChange : h.current[unit]}}" 
    data-time="{{$index}}">
        {{params.compare ? h.percentChange : h.current[unit]}}
</div>

它工作得很好. div中的h.current[unit]的作用是,它显示值(以十进制表示).这样..
但是,我需要将十进制值显示为整数.像这样... 我有一个intFormat函数可以做到这一点.例如: intFormat(79.952)将返回80.所以我正在尝试使用intFormat函数格式化热图中的数字.如何实现呢?我不知道这是否合法,但是我尝试了{{params.compare ? h.percentChange : intFormat(h.current[unit])}},但是它不起作用.我正在使用Angularjs 1X和KendoUI.我可以在双花括号内使用功能吗?

Its works perfectly fine. what the h.current[unit] inside the div, does is, it displays the value (in decimal notation). Like this..
However I need to display the decimal values as integers. Like this... And I have a intFormat function that does just that. For eg: intFormat(79.952) will return 80. So i'm trying to format the numbers inside the heatmap using the intFormat function. How to achieve this? I don't know if this is legal but I tried {{params.compare ? h.percentChange : intFormat(h.current[unit])}}, but its not working. I'm using Angularjs 1X and KendoUI. Can I use function inside the double curly brace?

推荐答案

您可以:

创建这样的函数

$scope.getDisplayValue = function(currentValue)
{
   return intFormat(currentValue);
}

然后在html中像这样引用它:

And then reference it like this in the html:

{{getDisplayValue(h.percentChange)}}

如果您有任何疑问,请告诉我.

Please let me know if you have any questions.

这篇关于角双花括号内的函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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