File
Metadata
selector |
app-navbar |
styleUrls |
navbar.component.css |
templateUrl |
navbar.component.html |
Methods
loginUser
|
loginUser()
|
Returns: void
|
logoutUser
|
logoutUser()
|
Returns: void
|
loggedIn
|
loggedIn()
|
Returns: void
|
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();
}
}