mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 23:34:42 +00:00
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
This commit is contained in:
parent
cde840fdf8
commit
2b344dbd20
2 changed files with 5 additions and 4 deletions
|
|
@ -443,6 +443,7 @@ function $RouteProvider(){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateRoute();
|
||||||
$rootScope.$on('$locationChangeSuccess', updateRoute);
|
$rootScope.$on('$locationChangeSuccess', updateRoute);
|
||||||
|
|
||||||
return $route;
|
return $route;
|
||||||
|
|
|
||||||
|
|
@ -389,7 +389,7 @@ describe('$route', function() {
|
||||||
var onChangeSpy = jasmine.createSpy('onChange');
|
var onChangeSpy = jasmine.createSpy('onChange');
|
||||||
|
|
||||||
$rootScope.$on('$routeChangeStart', onChangeSpy);
|
$rootScope.$on('$routeChangeStart', onChangeSpy);
|
||||||
expect($route.current).toBeUndefined();
|
expect($route.current).not.toBeUndefined();
|
||||||
expect(onChangeSpy).not.toHaveBeenCalled();
|
expect(onChangeSpy).not.toHaveBeenCalled();
|
||||||
|
|
||||||
$location.path('/unknownRoute');
|
$location.path('/unknownRoute');
|
||||||
|
|
@ -426,7 +426,7 @@ describe('$route', function() {
|
||||||
|
|
||||||
// init
|
// init
|
||||||
$rootScope.$on('$routeChangeStart', onChangeSpy);
|
$rootScope.$on('$routeChangeStart', onChangeSpy);
|
||||||
expect($route.current).toBeUndefined();
|
expect($route.current).not.toBeUndefined();
|
||||||
expect(onChangeSpy).not.toHaveBeenCalled();
|
expect(onChangeSpy).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -434,7 +434,7 @@ describe('$route', function() {
|
||||||
$location.path('/unknownRoute');
|
$location.path('/unknownRoute');
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
|
|
||||||
expect(currentRoute).toBeUndefined();
|
expect(currentRoute).not.toBeUndefined();
|
||||||
expect(nextRoute.templateUrl).toBe('404.html');
|
expect(nextRoute.templateUrl).toBe('404.html');
|
||||||
expect($route.current.templateUrl).toBe('404.html');
|
expect($route.current.templateUrl).toBe('404.html');
|
||||||
expect(onChangeSpy).toHaveBeenCalled();
|
expect(onChangeSpy).toHaveBeenCalled();
|
||||||
|
|
@ -770,7 +770,7 @@ describe('$route', function() {
|
||||||
var onChangeSpy = jasmine.createSpy('onChange');
|
var onChangeSpy = jasmine.createSpy('onChange');
|
||||||
|
|
||||||
$rootScope.$on('$routeChangeStart', onChangeSpy);
|
$rootScope.$on('$routeChangeStart', onChangeSpy);
|
||||||
expect($route.current).toBeUndefined();
|
expect($route.current).not.toBeUndefined();
|
||||||
expect(onChangeSpy).not.toHaveBeenCalled();
|
expect(onChangeSpy).not.toHaveBeenCalled();
|
||||||
|
|
||||||
$location.path('/');
|
$location.path('/');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue