fix(ngClass): handle index changes when an item is unshifted

Closes #7256
This commit is contained in:
Shahar Talmi
2014-04-26 17:17:50 +03:00
committed by Brian Ford
parent 63f284a55c
commit 5fbd618c2f
2 changed files with 23 additions and 1 deletions

View File

@@ -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) :

View File

@@ -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" ' +