This repository was archived by the owner on Apr 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.component.ts
More file actions
79 lines (71 loc) · 2.48 KB
/
app.component.ts
File metadata and controls
79 lines (71 loc) · 2.48 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
import {AfterViewInit, Component, ElementRef, Inject, OnInit, PLATFORM_ID, Renderer2, ViewChild} from '@angular/core';
import {Event, NavigationEnd, Router} from '@angular/router';
import {UsersService} from './users.service';
import {environment} from '../environments/environment';
import {NavService} from './nav.service';
import {GoogleAnalyticsService} from './google-analytics.service';
import {isPlatformBrowser} from '@angular/common';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
export class AppComponent implements OnInit, AfterViewInit {
@ViewChild('appDrawer') appDrawer: ElementRef;
private firstUseOfCurrentRoute: boolean = true;
constructor(public usersService: UsersService,
private router: Router,
public navService: NavService,
private gaService: GoogleAnalyticsService,
private renderer: Renderer2,
@Inject(PLATFORM_ID) private platformId: Object) {
if (environment.production) {
router.events.subscribe(
(event: Event) => {
if (event instanceof NavigationEnd) {
gaService.sendPageview(event.urlAfterRedirects);
}
}
);
}
}
ngOnInit() {
if (isPlatformBrowser(this.platformId)) {
// Don't scrollTop on pages that have previously been visited
window.onpopstate = (event: PopStateEvent) => {
this.firstUseOfCurrentRoute = false;
};
// scrollTop on newly visited pages
this.router.events.filter(event => event instanceof NavigationEnd)
.subscribe(() => {
if (this.firstUseOfCurrentRoute) {
const scrollingElement = document.scrollingElement || document.documentElement;
this.renderer.setProperty(scrollingElement, 'scrollTop', 0);
} else {
this.firstUseOfCurrentRoute = true;
}
});
}
}
ngAfterViewInit() {
this.navService.appDrawer = this.appDrawer;
}
logout() {
this.navService.closeNav();
this.usersService.logout();
}
openBlog() {
const url = 'https://blog.devintent.com';
this.navService.closeNav();
this.gaService.sendPageview('blog');
this.router.navigate(['/'])
.then(() => window.location.href = url);
}
sendFeedback() {
const url = 'https://www.devintent.com';
this.navService.closeNav();
this.gaService.sendPageview('submit_feedback');
this.router.navigate(['/'])
.then(() => window.location.href = url);
}
}