import {Component, OnInit} from "@angular/core"; import {Router} from "@angular/router"; import {LoginService} from "../services/app-user-service/login-service"; import {RouteConfig} from "../app.config"; @Component({ moduleId: module.id, templateUrl: 'login.component.html', styleUrls: ['login.component.css'] }) export class LoginComponent implements OnInit { showErrorLabel = false; error: string; loading = false; returnUrl: string; constructor(private router: Router, private loginService: LoginService) { } ngOnInit() { // reset login status this.loginService.logout(); // redirect on success this.returnUrl = RouteConfig.overviewPath; } login(username: string, password: string) { if (username.length > 0 && password.length > 0) { this.loading = true; this.loginService.login(username, password) .subscribe( data => { this.router.navigate([this.returnUrl]); }, error => { this.error = error._body; this.showErrorLabel = true; setTimeout(() => { this.showErrorLabel = false; }, 4000); this.loading = false; }); } } }