ngClassOdd / ngClassEven未正常工作 [英] ngClassOdd/ngClassEven not working as expected
问题描述
采用了棱角分明的版本1.2.15,我发现,它似乎开始了1.2.2版本,直到1.2.15的错误。
Using Angular version 1.2.15, I found a bug that it seems started on version 1.2.2 until 1.2.15.
HTML
<body ng-app="">
<ol ng-init="names=['John', 'Mary', 'Cate', 'Suz','Felipe','Vero']">
<li ng-repeat="name in names">
<span ng-class-odd="'shared odd'" ng-class-even="'shared even'">
{{name}}
</span>
</li>
</ol>
</body
CSS
.shared {color: red;}
.even{ background-color:yellow; }
.odd{ background-color:white; }
您将看到如何奇风格不三号元的工作。
You will see how the odd style does not work on the 3rd Element.
是否有此问题的任何解决方法吗?
Is there any workaround for this issue?
如果不是会更有意义升级或降级?
If not what would make more sense upgrade or downgrade?
推荐答案
这是一个已知的bug,并已得到修复,那么为什么不更新到 v1.2.16
<? BR>
它的工作原理为预期的 v1.2.16
。
This was a known bug and has been fixed, so why not update to v1.2.16
?
It works as expected on v1.2.16
.
如果你还想留下来的 v1.2.15
您应该要么使用摩根的解决方案(纳克级
+ $指数
),或包括在只有一个类 ngClassOdd
/ ngClassEven
:
If you want to stay on v1.2.15
you should either use Morgan's solution (ng-class
+ $index
), or include only one class in ngClassOdd
/ngClassEven
:
<span class="shared" ng-class-odd="'odd'" ng-class-even="'even'">
BTW,有在1.2.16版本(根据 <无重大更改href=\"https://github.com/angular/angular.js/blob/master/CHANGELOG.md#user-content-1.2.16\">changelog),所以升级应该是完全透明的。
BTW, there were no breaking changes in version 1.2.16 (according to the changelog), so upgrading should be totally transparent.
更新:
为了完整起见,我应该提到存在使用的选项 ngRepeat
的 $甚至
/ $奇
属性。例如:
For the sake of completeness, I should mention there is the option of using ngRepeat
's $even
/$odd
properties. E.g.:
<span ng-class="$even?'shared odd':'shared even'">
<子>
注意:结果
由于通过 ngRepeat
显示的项目列表是从0开始的,第一个元素( $指数:0
)被认为是奇怪,而我们(人类)期望能够甚至考虑的第一个因素。所以,确保应用类负。结果
同样是 ngClass + $指数
办法真。
Note:
Since the list of items displayed by ngRepeat
is 0-based, the 1st element ($index: 0
) is considered odd, while we (humans) expect the 1st element to be considered even. So, make sure you apply the classes "inversely".
The same is true for the ngClass + $index
approach.
推荐的解决方案仍然是升级到 v1.2.16
。结果
为以防万一, 是plunkr 与所有3 v1.2.15
解决方案。
The recommended solution is still to upgrade to v1.2.16
.
Just in case, here is a plunkr with all 3 v1.2.15
solutions.
这篇关于ngClassOdd / ngClassEven未正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!