gpt4 book ai didi

angularjs - 如何在 ng :pluralize 中格式化数字

转载 作者:行者123 更新时间:2023-12-04 05:54:11 24 4
gpt4 key购买 nike

如何格式化通过属性“count”传递给 ng:pluralize 指令的数字?

考虑以下代码:

<ng:pluralize count="5000000" when="{'other': '{} things'}"></pluralize>

输出是:
5000000 things

我如何修改它的输出为:
5,000,000 things    // in US locale
5 000 000 things // in Czech locale

我尝试使用过滤器“数字”,但我想我不知道把它放在哪里。它在传递给属性“when”的对象中不起作用。我试过这些:
... when="{'many': '{{{}|number}} things'}"
... when="{'many': '{}|number things'}"
... when="{'many': '{|number} things'}"

最佳答案

您需要将值分配给变量

 <ng:pluralize ng-init="myCount=5000000" count="myCount" when="{'other': '{{myCount|number}} things'}"></ng:pluralize>

这会将值格式化为当前区域设置规则

演示 :
  • plunker
  • 关于angularjs - 如何在 ng :pluralize 中格式化数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14002870/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com