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

Commit

Permalink
fix(ngClass): handle index changes when an item is unshifted
Browse files Browse the repository at this point in the history
Closes #7256
  • Loading branch information
shahata authored and btford committed May 16, 2014
1 parent 63f284a commit 5fbd618
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/directive/ngClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function classDirective(name, selector) {
scope.$watch('$index', function($index, old$index) {
// jshint bitwise: false
var mod = $index & 1;
if (mod !== old$index & 1) {
if (mod !== (old$index & 1)) {
var classes = arrayClasses(scope.$eval(attr[name]));
mod === selector ?
addClasses(classes) :
Expand Down
22 changes: 22 additions & 0 deletions test/ng/directive/ngClassSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,28 @@ describe('ngClass', function() {
}));


it('should update ngClassOdd/Even when an item is added to the model', inject(function($rootScope, $compile) {
element = $compile('<ul>' +
'<li ng-repeat="i in items" ' +
'ng-class-odd="\'odd\'" ng-class-even="\'even\'">i</li>' +
'<ul>')($rootScope);
$rootScope.items = ['b','c','d'];
$rootScope.$digest();

$rootScope.items.unshift('a');
$rootScope.$digest();

var e1 = jqLite(element[0].childNodes[1]);
var e4 = jqLite(element[0].childNodes[7]);

expect(e1.hasClass('odd')).toBeTruthy();
expect(e1.hasClass('even')).toBeFalsy();

expect(e4.hasClass('even')).toBeTruthy();
expect(e4.hasClass('odd')).toBeFalsy();
}));


it('should update ngClassOdd/Even when model is changed by filtering', inject(function($rootScope, $compile) {
element = $compile('<ul>' +
'<li ng-repeat="i in items track by $index" ' +
Expand Down

0 comments on commit 5fbd618

Please sign in to comment.