我见过的所有 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/