Skip to content

Commit c433502

Browse files
committed
Imporve navigation example
1 parent 227485b commit c433502

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

ng-sample/app/examples/navigation/nav-component.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import {Component} from 'angular2/core';
22
import {ROUTER_DIRECTIVES, Router, OnActivate, OnDeactivate, CanReuse, OnReuse,
33
LocationStrategy, RouteParams, ComponentInstruction, RouteConfig, Location } from 'angular2/router';
44
import {topmost} from "ui/frame";
5+
import {Page} from "ui/page";
56
import {NS_ROUTER_DIRECTIVES} from "../../nativescript-angular/router/ns-router";
67

78

89
@Component({
9-
selector: 'main',
10+
selector: 'master',
1011
template: `
1112
<StackLayout>
1213
<Label text="Master View" style="font-size: 20; horizontal-align: center; margin: 10"></Label>
@@ -15,22 +16,23 @@ import {NS_ROUTER_DIRECTIVES} from "../../nativescript-angular/router/ns-router"
1516
</StackLayout>
1617
`
1718
})
18-
class MainComp {
19+
class MasterComponent {
1920
public details: Array<number> = [1, 2, 3];
2021

2122
constructor(private _router: Router) {
23+
console.log("MasterComponent.constructor()");
2224
}
2325

2426
onSelect(val: number) {
2527
this._router.navigate(['../Detail', { id: val }]);
2628
}
2729

2830
routerOnActivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any {
29-
console.log("MainComp.routerOnActivate()")
31+
console.log("MasterComponent.routerOnActivate()")
3032
}
3133

3234
routerOnDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any {
33-
console.log("MainComp.routerOnDeactivate()")
35+
console.log("MasterComponent.routerOnDeactivate()")
3436
}
3537
}
3638

@@ -45,9 +47,10 @@ class MainComp {
4547
</StackLayout>
4648
`
4749
})
48-
class DetailComp {
50+
class DetailComponent {
4951
public id: number;
5052
constructor(params: RouteParams, private _router: Router) {
53+
console.log("DetailComponent.constructor()");
5154
this.id = parseInt(params.get("id"));
5255
}
5356

@@ -56,11 +59,11 @@ class DetailComp {
5659
}
5760

5861
routerOnActivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any {
59-
console.log("DetailComp.routerOnActivate() id: " + this.id)
62+
console.log("DetailComponent.routerOnActivate() id: " + this.id)
6063
}
6164

6265
routerOnDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any {
63-
console.log("DetailComp.routerOnDeactivate() id: " + this.id)
66+
console.log("DetailComponent.routerOnDeactivate() id: " + this.id)
6467
}
6568
}
6669

@@ -89,8 +92,8 @@ class DetailComp {
8992
`
9093
})
9194
@RouteConfig([
92-
{ path: '/', name: 'Main', component: MainComp, useAsDefault: true },
93-
{ path: '/:id', name: 'Detail', component: DetailComp }
95+
{ path: '/', name: 'Main', component: MasterComponent, useAsDefault: true },
96+
{ path: '/:id', name: 'Detail', component: DetailComponent }
9497
])
9598
export class NavComponent implements OnActivate, OnDeactivate {
9699
static counter: number = 0;
@@ -99,6 +102,7 @@ export class NavComponent implements OnActivate, OnDeactivate {
99102
public depth: number;
100103

101104
constructor(params: RouteParams, private location: Location) {
105+
console.log("NavComponent.constructor()");
102106
NavComponent.counter++;
103107

104108
this.compId = NavComponent.counter;

ng-sample/app/examples/navigation/navigation-test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from 'angular2/core';
2-
import {RouteConfig, ROUTER_PROVIDERS, ROUTER_DIRECTIVES} from 'angular2/router';
2+
import {RouteConfig, ROUTER_PROVIDERS, ROUTER_DIRECTIVES, ComponentInstruction} from 'angular2/router';
33

44
import {NavComponent} from "./nav-component";
55
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "../../nativescript-angular/router/ns-router";
@@ -15,7 +15,17 @@ import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "../../nativescript-angu
1515
`
1616
})
1717
class StartComponent {
18+
constructor() {
19+
console.log("StartComponent.constructor()")
20+
}
1821

22+
routerOnActivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any {
23+
console.log("StartComponent.routerOnActivate()")
24+
}
25+
26+
routerOnDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any {
27+
console.log("StartComponent.routerOnDeactivate()")
28+
}
1929
}
2030

2131
@Component({

0 commit comments

Comments
 (0)