From ca193d253a9e3199b98c1bcde552f4790b539061 Mon Sep 17 00:00:00 2001 From: Daniel Zimmermann Date: Wed, 8 Jan 2014 19:58:09 +1100 Subject: [PATCH] fix($route): update current route upon $route instantiation This fixes cases where the first ngView is loaded in a template asynchronously (such as through ngInclude), as the service will miss the first event otherwise. Closes #4957 --- src/ngRoute/route.js | 1 + test/ngRoute/routeSpec.js | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index e56faa3035eb..7f4221283106 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -443,6 +443,7 @@ function $RouteProvider(){ } }; + updateRoute(); $rootScope.$on('$locationChangeSuccess', updateRoute); return $route; diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index de7ccb8d593d..37b6a7b6f317 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -389,7 +389,7 @@ describe('$route', function() { var onChangeSpy = jasmine.createSpy('onChange'); $rootScope.$on('$routeChangeStart', onChangeSpy); - expect($route.current).toBeUndefined(); + expect($route.current).toBeDefined(); expect(onChangeSpy).not.toHaveBeenCalled(); $location.path('/unknownRoute'); @@ -426,7 +426,7 @@ describe('$route', function() { // init $rootScope.$on('$routeChangeStart', onChangeSpy); - expect($route.current).toBeUndefined(); + expect($route.current).toBeDefined(); expect(onChangeSpy).not.toHaveBeenCalled(); @@ -434,7 +434,7 @@ describe('$route', function() { $location.path('/unknownRoute'); $rootScope.$digest(); - expect(currentRoute).toBeUndefined(); + expect(currentRoute).toBeDefined(); expect(nextRoute.templateUrl).toBe('404.html'); expect($route.current.templateUrl).toBe('404.html'); expect(onChangeSpy).toHaveBeenCalled(); @@ -770,7 +770,7 @@ describe('$route', function() { var onChangeSpy = jasmine.createSpy('onChange'); $rootScope.$on('$routeChangeStart', onChangeSpy); - expect($route.current).toBeUndefined(); + expect($route.current).toBeDefined(); expect(onChangeSpy).not.toHaveBeenCalled(); $location.path('/');