Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 5fbd618

Browse files
shahatabtford
authored andcommitted
fix(ngClass): handle index changes when an item is unshifted
Closes #7256
1 parent 63f284a commit 5fbd618

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/ng/directive/ngClass.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function classDirective(name, selector) {
1919
scope.$watch('$index', function($index, old$index) {
2020
// jshint bitwise: false
2121
var mod = $index & 1;
22-
if (mod !== old$index & 1) {
22+
if (mod !== (old$index & 1)) {
2323
var classes = arrayClasses(scope.$eval(attr[name]));
2424
mod === selector ?
2525
addClasses(classes) :

test/ng/directive/ngClassSpec.js

+22
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,28 @@ describe('ngClass', function() {
276276
}));
277277

278278

279+
it('should update ngClassOdd/Even when an item is added to the model', inject(function($rootScope, $compile) {
280+
element = $compile('<ul>' +
281+
'<li ng-repeat="i in items" ' +
282+
'ng-class-odd="\'odd\'" ng-class-even="\'even\'">i</li>' +
283+
'<ul>')($rootScope);
284+
$rootScope.items = ['b','c','d'];
285+
$rootScope.$digest();
286+
287+
$rootScope.items.unshift('a');
288+
$rootScope.$digest();
289+
290+
var e1 = jqLite(element[0].childNodes[1]);
291+
var e4 = jqLite(element[0].childNodes[7]);
292+
293+
expect(e1.hasClass('odd')).toBeTruthy();
294+
expect(e1.hasClass('even')).toBeFalsy();
295+
296+
expect(e4.hasClass('even')).toBeTruthy();
297+
expect(e4.hasClass('odd')).toBeFalsy();
298+
}));
299+
300+
279301
it('should update ngClassOdd/Even when model is changed by filtering', inject(function($rootScope, $compile) {
280302
element = $compile('<ul>' +
281303
'<li ng-repeat="i in items track by $index" ' +

0 commit comments

Comments
 (0)