@@ -8,14 +8,28 @@ import {
88 APP_BASE_HREF
99} from 'angular2/router' ;
1010
11-
1211// #docregion routerOnActivate
13- @Component ( { selector : 'my-cmp' , template : `<div>routerOnActivate: {{log}}</div>` } )
14- class MyCmp implements OnActivate {
12+ @Component ( { template : `Child` } )
13+ class ChildCmp {
14+ }
15+
16+ @Component ( {
17+ template : `
18+ <h2>Parent</h2> (<router-outlet></router-outlet>)
19+ <p>{{log}}</p>` ,
20+ directives : [ ROUTER_DIRECTIVES ]
21+ } )
22+ @RouteConfig ( [ { path : '/child' , name : 'Child' , component : ChildCmp } ] )
23+ class ParentCmp implements OnActivate {
1524 log : string = '' ;
1625
1726 routerOnActivate ( next : ComponentInstruction , prev : ComponentInstruction ) {
1827 this . log = `Finished navigating from "${ prev ? prev . urlPath : 'null' } " to "${ next . urlPath } "` ;
28+
29+ return new Promise ( resolve => {
30+ // The ChildCmp gets instantiated only when the Promise is resolved
31+ setTimeout ( ( ) => resolve ( null ) , 1000 ) ;
32+ } ) ;
1933 }
2034}
2135// #enddocregion
@@ -24,23 +38,19 @@ class MyCmp implements OnActivate {
2438@Component ( {
2539 selector : 'example-app' ,
2640 template : `
27- <h1>My App</h1>
41+ <h1>My app</h1>
42+
2843 <nav>
29- <a [routerLink]="['/HomeCmp']" id="home-link">Navigate Home</a> |
30- <a [routerLink]="['/ParamCmp', {param: 1}]" id="param-link">Navigate with a Param</a>
44+ <a [routerLink]="['Parent', 'Child']">Child</a>
3145 </nav>
3246 <router-outlet></router-outlet>
3347 ` ,
3448 directives : [ ROUTER_DIRECTIVES ]
3549} )
36- @RouteConfig ( [
37- { path : '/' , component : MyCmp , name : 'HomeCmp' } ,
38- { path : '/:param' , component : MyCmp , name : 'ParamCmp' }
39- ] )
40- class AppCmp {
50+ @RouteConfig ( [ { path : '/parent/...' , name : 'Parent' , component : ParentCmp } ] )
51+ export class AppCmp {
4152}
4253
43-
4454export function main ( ) {
4555 return bootstrap (
4656 AppCmp , [ provide ( APP_BASE_HREF , { useValue : '/angular2/examples/router/ts/on_activate' } ) ] ) ;
0 commit comments