-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathsecond.component.ts
64 lines (54 loc) · 2.34 KB
/
second.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Component, OnInit, OnDestroy } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { RouterExtensions } from "nativescript-angular/router";
import { Page } from "tns-core-modules/ui/page";
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { CounterService } from "../counter.service";
@Component({
selector: "second",
template: `
<StackLayout>
<Label text="SecondComponent" class="header"></Label>
<Label [text]="'param: ' + (depth$ | async)" class="title"></Label>
<Button text="GO TO FIRST" [nsRouterLink]="['/first']"></Button>
<Button text="GO TO FIRST(CLEAR)" [nsRouterLink]="['/first']" clearHistory="true" pageTransition="flipRight"></Button>
<Button text="GO TO NEXT SECOND" [nsRouterLink]="['/second', (nextDepth$ | async)]"></Button>
<Button text="LOAD NESTED NAMED OUTLET" (tap)="loadNestedNamedOutlet()"></Button>
<Button text="BACK" automationText="BACK" (tap)="goBack()"></Button>
<Button text="TICK" automationText="TICK" (tap)="service.tick()"></Button>
<GridLayout row="1" rows="*,*">
<GridLayout row="0" class="nested-outlet">
<router-outlet></router-outlet>
</GridLayout>
<GridLayout row="1">
<page-router-outlet name="lazyNameOutlet"></page-router-outlet>
</GridLayout>
</GridLayout>
</StackLayout>`
})
export class SecondComponent implements OnInit, OnDestroy {
public depth$: Observable<string>;
public nextDepth$: Observable<number>;
constructor(
private routerExt: RouterExtensions,
private route: ActivatedRoute,
public service: CounterService,
page: Page) {
console.log("SecondComponent - constructor() page: " + page);
this.depth$ = route.params.pipe(map(r => r["depth"]));
this.nextDepth$ = route.params.pipe(map(r => +r["depth"] + 1));
}
ngOnInit() {
console.log("SecondComponent - ngOnInit()");
}
ngOnDestroy() {
console.log("SecondComponent - ngOnDestroy()");
}
goBack() {
this.routerExt.back({ relativeTo: this.route });
}
loadNestedNamedOutlet() {
this.routerExt.navigate([{ outlets: { lazyNameOutlet: ["lazy-named"] } }], { relativeTo: this.route });
}
}