From 3f568b22f9bec09192588e3cae937db5c2e757f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Thu, 17 Oct 2013 14:29:06 -0400 Subject: [PATCH] fix(ngView): ensure the new view element is placed after the old view element Closes #4362 --- src/ngRoute/directive/ngView.js | 6 +++--- test/ngRoute/directive/ngViewSpec.js | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ngRoute/directive/ngView.js b/src/ngRoute/directive/ngView.js index ab1327d0965e..3a296b5b1e44 100644 --- a/src/ngRoute/directive/ngView.js +++ b/src/ngRoute/directive/ngView.js @@ -207,10 +207,10 @@ function ngViewFactory( $route, $anchorScroll, $compile, $controller, if (template) { var newScope = scope.$new(); linker(newScope, function(clone) { - cleanupLastView(); - clone.html(template); - $animate.enter(clone, null, $element); + $animate.enter(clone, null, currentElement || $element); + + cleanupLastView(); var link = $compile(clone.contents()), current = $route.current; diff --git a/test/ngRoute/directive/ngViewSpec.js b/test/ngRoute/directive/ngViewSpec.js index 2d74760c5b90..bfcb0929a10a 100644 --- a/test/ngRoute/directive/ngViewSpec.js +++ b/test/ngRoute/directive/ngViewSpec.js @@ -599,9 +599,9 @@ describe('ngView animations', function() { $location.path('/bar'); $rootScope.$digest(); - var itemA = $animate.flushNext('leave').element; + var itemA = $animate.flushNext('enter').element; expect(itemA).not.toEqual(itemB); - var itemB = $animate.flushNext('enter').element; + var itemB = $animate.flushNext('leave').element; })); it('should render ngClass on ngView', @@ -635,8 +635,8 @@ describe('ngView animations', function() { $location.path('/bar'); $rootScope.$digest(); - $animate.flushNext('leave').element; - item = $animate.flushNext('enter').element; + $animate.flushNext('enter').element; + item = $animate.flushNext('leave').element; $animate.flushNext('addClass').element; $animate.flushNext('addClass').element; @@ -679,12 +679,11 @@ describe('ngView animations', function() { $location.path('/bar'); $rootScope.$digest(); + $animate.flushNext('enter'); //ngView new $animate.flushNext('leave'); //ngView old $rootScope.$digest(); - $animate.flushNext('enter'); //ngView new - expect(n(element.text())).toEqual(''); //this is midway during the animation $animate.flushNext('enter'); //ngRepeat 3