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

标签 angularjs

如何格式化通过属性“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/

    相关文章:

    javascript - 如何从angularjs http回调中查看json数据?

    javascript - Angularjs/Restangular,如何命名文件 blob 以供下载?

    javascript - 基于属性的 ng-options 模型绑定(bind)

    javascript - ionic 分页

    angularjs - 如何解决错误 “[$location:nobase] $location in HTML5 mode requires a <base> tag to be present!”

    javascript - 我可以创建一个 promise 来检查变量是否以 Angular 设置?

    angularjs - 如何在 AngularJS 中打开/关闭 $log.debug

    javascript - 为什么我对 PHP 文件的 Angular POST 请求返回 404?

    javascript - 即使过滤器工作, Angular 过滤器也会抛出 "Can' t interpolate"错误

    javascript - 将对象作为参数传递到 Angular ui-router