mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
fix(ngClass): handle index changes when an item is unshifted
Closes #7256
This commit is contained in:
@@ -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) :
|
||||
|
||||
@@ -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" ' +
|
||||
|
||||
Reference in New Issue
Block a user