File

src/app/components/navbar/navbar.component.ts

Metadata

selector app-navbar
styleUrls navbar.component.css
templateUrl navbar.component.html

Constructor

constructor(authService: AuthService, alertify: AlertifyService, router: Router)

Methods

loginUser
loginUser()
Returns: void
logoutUser
logoutUser()
Returns: void
loggedIn
loggedIn()
Returns: void

Properties

authService
authService: AuthService
userLoginModel
userLoginModel: any
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '../../_services/auth.service';
import { AlertifyService } from '../../_services/alertify.service';

@Component({
  selector: 'app-navbar',
  templateUrl: './navbar.component.html',
  styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {
  userLoginModel: any = {};
  constructor(public authService: AuthService, private alertify: AlertifyService, private router: Router) { }

  ngOnInit() {
  }

  loginUser() {
    this.authService.login(this.userLoginModel).subscribe(data => {
      this.alertify.success('logged in successfully');
    }, error => {
      this.alertify.error('failed to login');
    }, () => {
      this.router.navigate(['/home']);
    });
  }

  logoutUser() {
    this.authService.userToken = null;
    localStorage.removeItem('token');
    this.alertify.message('logged out');
  }

  //check if user is loggedin
  loggedIn() {
    return this.authService.loggedIn();
  }
}

results matching ""

    No results matching ""