From 5a43213e3f6f7418bd3c7e00d8bcbba3bb202979 Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Sat, 26 Apr 2014 17:17:50 +0300 Subject: [PATCH] fix(ngClass): handle index change correctly changed the odd/even calculation to be done using modulo operation instead of bitwise operation. the bitwise operation caused issues with operator precedence (`mod !== old$index & 1` is actually parsed as `(mod !== old$index) & 1` and not `mod !== (old$index & 1)` as might be expected). decided it is better to just use modulo operation for readability instead of adding parentheses. fixes #7256 --- src/ng/directive/ngClass.js | 5 ++--- test/ng/directive/ngClassSpec.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ng/directive/ngClass.js b/src/ng/directive/ngClass.js index b00dbc666406..9ae92e12daac 100644 --- a/src/ng/directive/ngClass.js +++ b/src/ng/directive/ngClass.js @@ -17,9 +17,8 @@ function classDirective(name, selector) { if (name !== 'ngClass') { scope.$watch('$index', function($index, old$index) { - // jshint bitwise: false - var mod = $index & 1; - if (mod !== old$index & 1) { + var mod = $index % 2; + if (mod !== old$index % 2) { var classes = arrayClasses(scope.$eval(attr[name])); mod === selector ? addClasses(classes) : diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index 74de76d6555d..a5a60b35300a 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -276,6 +276,27 @@ describe('ngClass', function() { })); + it('should update ngClassOdd/Even when model is changed by adding', inject(function($rootScope, $compile) { + element = $compile('