From 0ac969a5ee1687cfd4517821943f34fe948bb3fc Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 16 Apr 2013 12:29:56 +0100 Subject: fix(ngClass): should remove classes when object is the same but property has changed If you wire up ngClass directly to an object on the scope, e.g. ng-class="myClasses", where scope.myClasses = { 'classA': true, 'classB': false }, there was a bug that changing scope.myClasses.classA = false, was not being picked up and classA was not being removed from the element's CSS classes. This fix uses angular.equals for the comparison and ensures that oldVal is a copy of (rather than a reference to) the newVal. --- src/ng/directive/ngClass.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ng/directive/ngClass.js b/src/ng/directive/ngClass.js index d731118f..09efe0c8 100644 --- a/src/ng/directive/ngClass.js +++ b/src/ng/directive/ngClass.js @@ -29,12 +29,12 @@ function classDirective(name, selector) { function ngClassWatchAction(newVal) { if (selector === true || scope.$index % 2 === selector) { - if (oldVal && (newVal !== oldVal)) { + if (oldVal && !equals(newVal,oldVal)) { removeClass(oldVal); } addClass(newVal); } - oldVal = newVal; + oldVal = copy(newVal); } -- cgit v1.2.3