From 4d40a4f962f032c25c8a446f0512b213a39c12e0 Mon Sep 17 00:00:00 2001 From: Grant Berridge Date: Thu, 17 Oct 2013 15:24:24 +1300 Subject: [PATCH] Fix ngShow and ngHide so that the directives don't animate in/out their classes every time the watch expression is evaluated. They now only change when the watch expression's boolean value actually changes. This is to address issue #4401 --- src/ng/directive/ngShowHide.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ng/directive/ngShowHide.js b/src/ng/directive/ngShowHide.js index cdfa060421ca..bd1f7a6ffdbb 100644 --- a/src/ng/directive/ngShowHide.js +++ b/src/ng/directive/ngShowHide.js @@ -145,8 +145,12 @@ */ var ngShowDirective = ['$animate', function($animate) { return function(scope, element, attr) { - scope.$watch(attr.ngShow, function ngShowWatchAction(value){ - $animate[toBoolean(value) ? 'removeClass' : 'addClass'](element, 'ng-hide'); + var watchHasNeverFired = true; + scope.$watch(attr.ngShow, function ngShowWatchAction(value, oldValue){ + if (watchHasNeverFired || (toBoolean(value) !== toBoolean(oldValue))) { + watchHasNeverFired = false; + $animate[toBoolean(value) ? 'removeClass' : 'addClass'](element, 'ng-hide'); + } }); }; }]; @@ -297,8 +301,11 @@ var ngShowDirective = ['$animate', function($animate) { */ var ngHideDirective = ['$animate', function($animate) { return function(scope, element, attr) { - scope.$watch(attr.ngHide, function ngHideWatchAction(value){ - $animate[toBoolean(value) ? 'addClass' : 'removeClass'](element, 'ng-hide'); + var watchHasNeverFired = true; + scope.$watch(attr.ngHide, function ngHideWatchAction(value, oldValue){ + if (watchHasNeverFired || (toBoolean(value) !== toBoolean(oldValue))) { + $animate[toBoolean(value) ? 'addClass' : 'removeClass'](element, 'ng-hide'); + } }); }; }];