Projekt

Obecné

Profil

Stáhnout (845 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1 2c5da396 hlavja
import {Component, OnDestroy, OnInit} from '@angular/core';
2 464309d9 hlavja
import {AuthService} from '../../../auth/services/auth.service';
3 2c5da396 hlavja
import {User} from '../../../auth/models/user';
4
import {Subscription} from 'rxjs';
5 464309d9 hlavja
6
@Component({
7
  selector: 'app-nav-bar',
8
  templateUrl: './nav-bar.component.html',
9
  styleUrls: ['./nav-bar.component.scss']
10
})
11 2c5da396 hlavja
export class NavBarComponent implements OnInit, OnDestroy {
12 464309d9 hlavja
13 2c5da396 hlavja
  loggedUser: User;
14
  subscription: Subscription[] = [];
15 464309d9 hlavja
  constructor(
16 2c5da396 hlavja
    private authService: AuthService
17 464309d9 hlavja
  ) {
18
  }
19
20
  ngOnInit(): void {
21 2c5da396 hlavja
    this.setUser();
22
  }
23
24
  setUser(){
25
    this.authService.getUserState().subscribe(res => {
26
      if(res){
27
        this.loggedUser = res;
28
      }
29
    });
30 464309d9 hlavja
  }
31
32
  logOut(): void {
33
    this.authService.doLogout();
34
  }
35 2c5da396 hlavja
36
  ngOnDestroy(): void {
37
    this.subscription.forEach(subs => subs.unsubscribe());
38
  }
39 464309d9 hlavja
}