-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathapp.component.ts
37 lines (36 loc) · 1.04 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
import { Component, inject, signal } from '@angular/core';
import {
ActivatedRoute,
NavigationEnd,
NavigationStart,
Router,
RouterModule,
} from '@angular/router';
import { HeaderComponent } from './layout/header/header.component';
import { FooterComponent } from './layout/footer/footer.component';
import { filter, startWith, tap } from 'rxjs';
import { NgIf } from '@angular/common';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrl: './app.component.scss',
imports: [NgIf, RouterModule, HeaderComponent, FooterComponent]
})
export class AppComponent {
router = inject(Router);
loading = signal(false);
ngOnInit() {
this.router.events
.pipe(
startWith(this.router.events),
filter(
(event) =>
event instanceof NavigationEnd || event instanceof NavigationStart
),
tap(() => this.loading.set(true)),
filter((event) => event instanceof NavigationEnd),
tap(() => this.loading.set(false))
)
.subscribe();
}
}