| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 15:53:37 -07:00
										 |  |  | describe('navigation', function () { | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   var elt, | 
					
						
							|  |  |  |       $compile, | 
					
						
							|  |  |  |       $rootScope, | 
					
						
							|  |  |  |       $router, | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       $compileProvider; | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   beforeEach(function () { | 
					
						
							|  |  |  |     module('ng'); | 
					
						
							|  |  |  |     module('ngComponentRouter'); | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     module(function (_$compileProvider_) { | 
					
						
							|  |  |  |       $compileProvider = _$compileProvider_; | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     inject(function (_$compile_, _$rootScope_, _$router_) { | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |       $compile = _$compile_; | 
					
						
							|  |  |  |       $rootScope = _$rootScope_; | 
					
						
							|  |  |  |       $router = _$router_; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     registerComponent('userCmp', { | 
					
						
							|  |  |  |       template: '<div>hello {{userCmp.$routeParams.name}}</div>' | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     registerComponent('oneCmp', { | 
					
						
							|  |  |  |       template: '<div>{{oneCmp.number}}</div>', | 
					
						
							|  |  |  |       controller: function () {this.number = 'one'} | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     registerComponent('twoCmp', { | 
					
						
							|  |  |  |       template: '<div>{{twoCmp.number}}</div>', | 
					
						
							|  |  |  |       controller: function () {this.number = 'two'} | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should work in a simple case', function () { | 
					
						
							|  |  |  |     compile('<ng-outlet></ng-outlet>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $router.config([ | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       { path: '/', component: 'oneCmp' } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |     $router.navigateByUrl('/'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(elt.text()).toBe('one'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should navigate between components with different parameters', function () { | 
					
						
							|  |  |  |     $router.config([ | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       { path: '/user/:name', component: 'userCmp' } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     ]); | 
					
						
							|  |  |  |     compile('<ng-outlet></ng-outlet>'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |     $router.navigateByUrl('/user/brian'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  |     expect(elt.text()).toBe('hello brian'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |     $router.navigateByUrl('/user/igor'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  |     expect(elt.text()).toBe('hello igor'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |   it('should reuse a parent when navigating between child components with different parameters', function () { | 
					
						
							|  |  |  |     var instanceCount = 0; | 
					
						
							|  |  |  |     function ParentController() { | 
					
						
							|  |  |  |       instanceCount += 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     registerComponent('parentCmp', { | 
					
						
							|  |  |  |       template: 'parent { <ng-outlet></ng-outlet> }', | 
					
						
							|  |  |  |       $routeConfig: [ | 
					
						
							|  |  |  |         { path: '/user/:name', component: 'userCmp' } | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |       controller: ParentController | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $router.config([ | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       { path: '/parent/...', component: 'parentCmp' } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     ]); | 
					
						
							|  |  |  |     compile('<ng-outlet></ng-outlet>'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |     $router.navigateByUrl('/parent/user/brian'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     expect(instanceCount).toBe(1); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     expect(elt.text()).toBe('parent { hello brian }'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |     $router.navigateByUrl('/parent/user/igor'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     expect(instanceCount).toBe(1); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     expect(elt.text()).toBe('parent { hello igor }'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should work with nested outlets', function () { | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     registerComponent('childCmp', { | 
					
						
							|  |  |  |       template: '<div>inner { <div ng-outlet></div> }</div>', | 
					
						
							|  |  |  |       $routeConfig: [ | 
					
						
							|  |  |  |         { path: '/b', component: 'oneCmp' } | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $router.config([ | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       { path: '/a/...', component: 'childCmp' } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     ]); | 
					
						
							|  |  |  |     compile('<div>outer { <div ng-outlet></div> }</div>'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |     $router.navigateByUrl('/a/b'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(elt.text()).toBe('outer { inner { one } }'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |   // TODO: fix this
 | 
					
						
							|  |  |  |   xit('should work with recursive nested outlets', function () { | 
					
						
							|  |  |  |     registerComponent('recurCmp', { | 
					
						
							|  |  |  |       template: '<div>recur { <div ng-outlet></div> }</div>', | 
					
						
							|  |  |  |       $routeConfig: [ | 
					
						
							|  |  |  |         { path: '/recur', component: 'recurCmp' }, | 
					
						
							|  |  |  |         { path: '/end', component: 'oneCmp' } | 
					
						
							|  |  |  |       ]}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $router.config([ | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       { path: '/recur', component: 'recurCmp' }, | 
					
						
							|  |  |  |       { path: '/', component: 'oneCmp' } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     compile('<div>root { <div ng-outlet></div> }</div>'); | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     $router.navigateByUrl('/recur/recur/end'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  |     expect(elt.text()).toBe('root { one }'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should change location path', inject(function ($location) { | 
					
						
							|  |  |  |     $router.config([ | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       { path: '/user', component: 'userCmp' } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     compile('<div ng-outlet></div>'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |     $router.navigateByUrl('/user'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect($location.path()).toBe('/user'); | 
					
						
							|  |  |  |   })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should change location to the canonical route', inject(function ($location) { | 
					
						
							|  |  |  |     compile('<div ng-outlet></div>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $router.config([ | 
					
						
							|  |  |  |       { path: '/',     redirectTo: '/user' }, | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       { path: '/user', component:  'userCmp' } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     ]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |     $router.navigateByUrl('/'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect($location.path()).toBe('/user'); | 
					
						
							|  |  |  |   })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should change location to the canonical route with nested components', inject(function ($location) { | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     registerComponent('childRouter', { | 
					
						
							|  |  |  |       template: '<div>inner { <div ng-outlet></div> }</div>', | 
					
						
							|  |  |  |       $routeConfig: [ | 
					
						
							|  |  |  |         { path: '/old-child', redirectTo: '/new-child' }, | 
					
						
							|  |  |  |         { path: '/new-child', component: 'oneCmp'}, | 
					
						
							|  |  |  |         { path: '/old-child-two', redirectTo: '/new-child-two' }, | 
					
						
							|  |  |  |         { path: '/new-child-two', component: 'twoCmp'} | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $router.config([ | 
					
						
							|  |  |  |       { path: '/old-parent', redirectTo: '/new-parent' }, | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       { path: '/new-parent/...', component:  'childRouter' } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     compile('<div ng-outlet></div>'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |     $router.navigateByUrl('/old-parent/old-child'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect($location.path()).toBe('/new-parent/new-child'); | 
					
						
							|  |  |  |     expect(elt.text()).toBe('inner { one }'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 21:41:56 -07:00
										 |  |  |     $router.navigateByUrl('/old-parent/old-child-two'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect($location.path()).toBe('/new-parent/new-child-two'); | 
					
						
							|  |  |  |     expect(elt.text()).toBe('inner { two }'); | 
					
						
							|  |  |  |   })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should navigate when the location path changes', inject(function ($location) { | 
					
						
							|  |  |  |     $router.config([ | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       { path: '/one', component: 'oneCmp' } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     ]); | 
					
						
							|  |  |  |     compile('<div ng-outlet></div>'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $location.path('/one'); | 
					
						
							|  |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(elt.text()).toBe('one'); | 
					
						
							|  |  |  |   })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should expose a "navigating" property on $router', inject(function ($q) { | 
					
						
							|  |  |  |     var defer; | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     registerComponent('pendingActivate', { | 
					
						
							|  |  |  |       $canActivate: function () { | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |         defer = $q.defer(); | 
					
						
							|  |  |  |         return defer.promise; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     $router.config([ | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |       { path: '/pending-activate', component: 'pendingActivate' } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     ]); | 
					
						
							|  |  |  |     compile('<div ng-outlet></div>'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     $router.navigateByUrl('/pending-activate'); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  |     expect($router.navigating).toBe(true); | 
					
						
							|  |  |  |     defer.resolve(); | 
					
						
							|  |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  |     expect($router.navigating).toBe(false); | 
					
						
							|  |  |  |   })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |   function registerComponent(name, options) { | 
					
						
							|  |  |  |     var controller = options.controller || function () {}; | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     ['$onActivate', '$onDeactivate', '$onReuse', '$canReuse', '$canDeactivate'].forEach(function (hookName) { | 
					
						
							|  |  |  |       if (options[hookName]) { | 
					
						
							|  |  |  |         controller.prototype[hookName] = options[hookName]; | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function factory() { | 
					
						
							|  |  |  |       return { | 
					
						
							|  |  |  |         template: options.template || '', | 
					
						
							|  |  |  |         controllerAs: name, | 
					
						
							|  |  |  |         controller: controller | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     if (options.$canActivate) { | 
					
						
							|  |  |  |       factory.$canActivate = options.$canActivate; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (options.$routeConfig) { | 
					
						
							|  |  |  |       factory.$routeConfig = options.$routeConfig; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												refactor(angular_1_router): use directives for route targets
BREAKING CHANGE:
Previously, route configuration took a controller constructor function as the value of
`component` in a route definition:
```
$route.config([
  { route: '/', component: MyController }
])
```
Based on the name of the controller, we used to use a componentMapper service to
determine what template to pair with each controller, how to bind the instance to
the $scope.
To make the 1.x router more semantically alligned with Angular 2, we now route to a directive.
Thus a route configuration takes a normalized directive name:
```
$route.config([
  { route: '/', component: 'myDirective' }
])
```
BREAKING CHANGE:
In order to avoid name collisions, lifecycle hooks are now prefixed with `$`. Before:
```
MyController.prototype.onActivate = ...
```
After:
```
MyController.prototype.$onActivate = ...
```
Same for `$canActivate` (which now lives on the directive factory function),
`$canDeactivate`, `$canReuse`, and `$onDeactivate` hooks.
											
										 
											2015-09-18 15:53:50 -07:00
										 |  |  |     $compileProvider.directive(name, factory); | 
					
						
							| 
									
										
										
										
											2015-08-20 14:26:57 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   function compile(template) { | 
					
						
							|  |  |  |     elt = $compile('<div>' + template + '</div>')($rootScope); | 
					
						
							|  |  |  |     $rootScope.$digest(); | 
					
						
							|  |  |  |     return elt; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }); |