-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathhome.component.ts
More file actions
80 lines (73 loc) · 2.04 KB
/
home.component.ts
File metadata and controls
80 lines (73 loc) · 2.04 KB
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
73
74
75
76
77
78
79
80
import { Component, inject, NgZone, NO_ERRORS_SCHEMA, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterExtensions, NativeScriptCommonModule } from '@nativescript/angular';
import { EventData, Page, TabView } from '@nativescript/core';
@Component({
selector: 'demo-home',
templateUrl: './home.component.html',
imports: [NativeScriptCommonModule],
schemas: [NO_ERRORS_SCHEMA],
})
export class HomeComponent implements OnInit {
private _ngZone = inject(NgZone);
// vcRef: ViewContainerRef,
private _activeRoute = inject(ActivatedRoute);
private _page = inject(Page);
private _ngRouter = inject(Router);
private _router = inject(RouterExtensions);
tabItems: { [key: string]: { index: number; title?: string; iconSource?: string; textTransform?: string } } = {};
private _tabs = ['start'];
private _hasInitTab: { start?: boolean } = {};
private _tabView: TabView;
constructor() {
this._initMenu();
}
ngOnInit() {
this._viewTab(0);
}
onIndexChanged(e) {
if (e && e.object) {
this._tabView = <TabView>e.object;
}
}
private _viewTab(index: number) {
let route;
switch (index) {
case 0:
if (!this._hasInitTab.start) {
this._hasInitTab.start = true;
route = { outlets: { startTab: ['start'] } };
}
break;
}
console.log('tab index changed:', index);
this._ngZone.run(() => {
if (route) {
this._router.navigate([route], {
animated: false,
relativeTo: this._activeRoute,
});
}
});
}
private _initMenu() {
for (let i = 0; i < this._tabs.length; i++) {
const tab = this._tabs[i];
// console.log('================')
// console.log(tab)
// console.log(i);
// console.log(tab);
let title = '';
switch (tab) {
case 'start':
title = 'Start Tab';
break;
}
this.tabItems[tab] = {
index: i,
title,
textTransform: 'capitalize',
};
}
}
}