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 - 使用 javascript 合并颜色

javascript - 动态AngularJS验证与IP地址匹配,但最后一个八位位组在特定范围内

javascript - 通过T-SQL查询或C#或Javascript/AngularJs从多个列和行中获取具有最高日期的记录1

javascript - 使用ng-repeat的数据

javascript - 将数组转换为带有子对象的对象

javascript - AngularJs 中的隐藏字段

javascript - 提交后如何停止重新加载页面

java - 创建我自己的文档查看器

javascript - 收到正则表达式匹配的真假答案?

javascript - 我可以在 Firebase 身份验证中验证电子邮件的域区域吗?