forked from PatrickJS/PatrickJS-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.component.ts
106 lines (97 loc) · 3.24 KB
/
app.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Angular 2 decorators and services
*/
import {
Component,
OnInit,
ViewEncapsulation,
OnDestroy
} from '@angular/core';
import { AppState } from './app.service';
import { AuthService } from './login/auth.service';
import { Router, NavigationEnd } from '@angular/router';
import { Subscription } from 'rxjs';
/*
* App Component
* Top Level Component
*/
@Component({
selector: 'app',
encapsulation: ViewEncapsulation.Emulated,
styleUrls: [
'./app.component.css'
],
template: `
<nav>
<span [hidden]="!authService.isLoggedIn">
<span>
<a [routerLink]=" ['./login'] " routerLinkActive="active">
{{ authService.isLoggedIn ? 'Logout' : 'Login' }}
</a>
</span>
</span>
<span>
<a [routerLink]=" ['./home'] " routerLinkActive="active">
Home
</a>
</span>
<span>
<a [routerLink]=" ['./detail'] " routerLinkActive="active">
Detail
</a>
</span>
<span>
<a [routerLink]=" ['./barrel'] " routerLinkActive="active">
Barrel
</a>
</span>
<span>
<a [routerLink]=" ['./about'] " routerLinkActive="active">
About
</a>
</span>
</nav>
<main>
<router-outlet></router-outlet>
</main>
<div [hidden]="activeUrl === '/login'">
<div class="miscApp">[app] miscApp, activeUrl: {{activeUrl}}</div>
<img src="../images/fullscreen2.jpg" height="20px">
[home] <code><img src="../images/fullscreen2.jpg"></code> -> NO image-uri hash used!!! (broken link in production)<br>
<img src="../assets/img/angularclass-avatar.png" height="20px">
[app] <code><img src="../assets/img/angularclass-avatar.png></code> -> NO image-uri hash used!!! (broken link in production)<br>
<img src="assets/img/angularclass-avatar.png" height="20px">
[app] <code><img src="assets/img/angularclass-avatar.png></code> -> NO image-uri hash used!!!<br>
<img [src]="angularClassLogo" height="20px">
[app] <code>public angularClassLogo = 'assets/img/angularclass-avatar.png';</code> -> NO image-uri hash used!!!<br>
<pre class="app-state">[app] this.appState.state = {{ appState.state | json }}</pre>
</div>
`
})
export class AppComponent implements OnInit, OnDestroy {
public angularClassLogo = 'assets/img/angularclass-avatar.png';
public activeUrl: string;
private subscription: Subscription;
constructor(public appState: AppState,
public authService: AuthService,
private router: Router) {
// console.log('[app] constructor');
}
public ngOnInit() {
// console.log('[app] ngOnInit, Initial App State', this.appState.state);
// "this" in "function (s)" is NOT AppComponent.this !!!
let _this = this;
this.subscription = this.router.events.subscribe(function (s) {
if (s instanceof NavigationEnd) {
// console.log('[app] s: activeUrl = ' + s.urlAfterRedirects);
// console.log('[app] s: ' + JSON.stringify(s));
_this.activeUrl = s.urlAfterRedirects;
_this.appState.set('activeUrl', s.urlAfterRedirects);
}
});
}
public ngOnDestroy() {
// console.log('[app] ngOnDestroy: ');
this.subscription.unsubscribe();
}
}