javascript - ng-pluralize "when"绑定(bind)到一个变量

标签 javascript angularjs

我见过的所有 Angular 示例都使用文字“when”参数演示了 ng-pluralize:

<ng-pluralize count="x" when="{'one': 'thing', 'other': 'things'}"></ng-pluralize>

是否可以使用范围变量作为 when 属性?例如:

<ng-pluralize count="x" when="things"></ng-pluralize>

其中 $scope.things 设置为 {'one': 'thing', 'other': 'things'}

我已经试过了,但它没有像我在这里指定的那样工作,但我希望我只是遗漏了一些东西,这是可能的。

最佳答案

所以我刚刚发现,虽然您不能有效地将变量放入 when 属性中(可以,但不会反射(reflect)更新),但您可以这样做:

<ng-pluralize count="modalUsers.length" 
  when="{ 'one': '{{ templateConfig.pluralizeConfig.one }}',
          'other': '{{ templateConfig.pluralizeConfig.other }}' }">
</ng-pluralize>

然后更新templateConfig 对象。

关于javascript - ng-pluralize "when"绑定(bind)到一个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22339108/

相关文章:

javascript src 文件 404(未找到)

javascript - 带有参数的函数值的 JSON

javascript - 迭代 URL 并根据需要添加/替换字符串

node.js - 使用 Karma 进行 AngularJS 测试

javascript - AngularJS - 在文件输入上将图像加载到 img 标签

javascript - 在 AngularJS 路由中使用常量

javascript - 从组件数组中删除组件

javascript - IE9 无法获取未定义或空引用的属性 'remove'

Javascript 年龄验证

javascript - angularJS 在 ng-view 中加载非 Angular javascript 文件