forked from NativeScript/nativescript-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst.component.ts
72 lines (60 loc) · 2.44 KB
/
first.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
65
66
67
68
69
70
71
72
import { Component, OnInit, OnDestroy, OnChanges, DoCheck } from "@angular/core";
import { RouterExtensions } from "nativescript-angular/router";
import { Page } from "tns-core-modules/ui/page";
import { CounterService } from "../counter.service";
import { ActivatedRoute } from "@angular/router";
import { Subscription } from "rxjs";
@Component({
selector: "first",
template: `
<StackLayout>
<Label text="FirstComponent" class="header"></Label>
<Button text="GO TO SECOND" automationText="GO TO SECOND" [nsRouterLink]="['/second','1']" [queryParams]="{prop: 'xxx'}"></Button>
<Button text="GO TO C-LESS SECOND" automationText="GO TO C-LESS SECOND" [nsRouterLink]="['/c-less', 'deep', '100', 'detail', '200']"></Button>
<Button text="GO TO LAZY HOME" automationText="GO TO LAZY HOME" [nsRouterLink]="['/lazy','home']"></Button>
<Button text="GO TO C-LESS LAZY" automationText="GO TO C-LESS LAZY" [nsRouterLink]="['/lazy','nest','more']"></Button>
<Button text="BACK" automationText="BACK" (tap)="goBack()"></Button>
<Button text="RESET" automationText="RESET" (tap)="reset()"></Button>
<Label [text]="message"></Label>
<Label [text]="'CHECK: ' + doCheckCount"></Label>
<Label [text]="'COUNTER: ' + (service.counter$ | async)"></Label>
</StackLayout>`
})
export class FirstComponent implements OnInit, OnDestroy, DoCheck {
public message: string = "";
public doCheckCount: number = 0;
sub: Subscription;
constructor(
private routerExt: RouterExtensions,
private route: ActivatedRoute,
public service: CounterService,
page: Page) {
console.log("FirstComponent - constructor() page: " + page);
}
ngOnInit() {
console.log("FirstComponent - ngOnInit()");
this.sub = this.route.queryParams.subscribe((params) =>{
console.log("FIRST PARAMS:");
console.log(params);
});
}
ngOnDestroy() {
this.sub.unsubscribe();
console.log("FirstComponent - ngOnDestroy()");
}
ngDoCheck() {
this.doCheckCount++;
console.log("FirstComponent - ngDoCheck(): " + this.doCheckCount);
}
reset() {
this.doCheckCount = 0;
}
goBack() {
this.message = "";
if (this.routerExt.canGoBack()) {
this.routerExt.back();
} else {
this.message = "canGoBack() - false"
}
}
}