Projekt

Obecné

Profil

Stáhnout (845 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1
import {Component, OnDestroy, OnInit} from '@angular/core';
2
import {AuthService} from '../../../auth/services/auth.service';
3
import {User} from '../../../auth/models/user';
4
import {Subscription} from 'rxjs';
5

    
6
@Component({
7
  selector: 'app-nav-bar',
8
  templateUrl: './nav-bar.component.html',
9
  styleUrls: ['./nav-bar.component.scss']
10
})
11
export class NavBarComponent implements OnInit, OnDestroy {
12

    
13
  loggedUser: User;
14
  subscription: Subscription[] = [];
15
  constructor(
16
    private authService: AuthService
17
  ) {
18
  }
19

    
20
  ngOnInit(): void {
21
    this.setUser();
22
  }
23

    
24
  setUser(){
25
    this.authService.getUserState().subscribe(res => {
26
      if(res){
27
        this.loggedUser = res;
28
      }
29
    });
30
  }
31

    
32
  logOut(): void {
33
    this.authService.doLogout();
34
  }
35

    
36
  ngOnDestroy(): void {
37
    this.subscription.forEach(subs => subs.unsubscribe());
38
  }
39
}
(3-3/3)