Guest User

Untitled

a guest
Apr 22nd, 2018
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export class AuthService {
  2.     public user$ = new BehaviorSubject<User>(null)
  3.     login (username: string, password: string): void {
  4.         this.httpClient.post<ApiKey>(environment.apiUrl + '/login').subscribe(
  5.             (user) => {
  6.                 this.user$.next(user)
  7.             }
  8.         )
  9.     }
  10. }
  11.  
  12. export class AuthLoginComponent {
  13.     constructor (private authService: AuthService) {
  14.         this.authService.login()
  15.     }
  16. }
  17.  
  18. export class NavbarComponent {
  19.     constructor (private authService: AuthService) {
  20.         this.authService.user$.subscribe(
  21.             (user) => {
  22.                 console.log(user)
  23.             }
  24.         )
  25.     }
  26. }
Add Comment
Please, Sign In to add comment