最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - function call inside Angular double curly braces - Stack Overflow

programmeradmin4浏览0评论

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="{{paramspare ? h.percentChange : h.current[unit]}}" 
    data-time="{{$index}}">
        {{paramspare ? h.percentChange : h.current[unit]}}
</div>

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 {{paramspare ? 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?

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.pare ? h.percentChange : h.current[unit]}}" 
    data-time="{{$index}}">
        {{params.pare ? h.percentChange : h.current[unit]}}
</div>

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.pare ? 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?

Share Improve this question asked Oct 14, 2016 at 8:14 anoop chandrananoop chandran 1,5005 gold badges25 silver badges44 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 11

Sure you can:

create a function like this

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

And then reference it like this in the html:

{{getDisplayValue(h.percentChange)}}

Please let me know if you have any questions.

You can try using parseInt(10.5555), built in JavaScript convertor in your AngularJS Expression like this: {{parseInt(10.5555)}}.

Hope this helps. Thanks.

I was able to fix this by attaching a filter..like this...
{{params.pare ? h.percentChange : h.current[unit]|numFmt}}

发布评论

评论列表(0)

  1. 暂无评论