Skip to content

Instantly share code, notes, and snippets.

@iamburakcoskun
Created October 29, 2019 09:41
Show Gist options
  • Save iamburakcoskun/52447a0e8689fef9fe199313471ab78d to your computer and use it in GitHub Desktop.
Save iamburakcoskun/52447a0e8689fef9fe199313471ab78d to your computer and use it in GitHub Desktop.
import { Component, OnInit } from "@angular/core";
import { AuthService } from "../_services/auth.service";
import { AlertifyService } from "../_services/alertify.service";
@Component({
selector: "app-nav",
templateUrl: "./nav.component.html",
styleUrls: ["./nav.component.css"]
})
export class NavComponent implements OnInit {
constructor(
private authService: AuthService,
private alertifyService: AlertifyService
) {}
model: any = {};
login() {
this.authService.login(this.model).subscribe(
next => {
this.alertifyService.success("Logged in successfully!");
},
error => {
this.alertifyService.error("Failed to login..");
}
);
}
loggedIn() {
const token = localStorage.getItem("token");
return !!token;
}
logOut() {
localStorage.removeItem("token");
this.alertifyService.success("Logged out successfully!");
}
ngOnInit() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment