import { Http } from '@angular/http'; import { Router } from '@angular/router'; import { AfterViewInit, Component, Input } from '@angular/core'; import { UserService } from './user.service'; import { ToastsManager } from 'ng2-toastr/ng2-toastr'; class LoginData { username: string; password: string; } @Component({ selector: 'login-form', templateUrl: "src/app/login.form.html" }) export class LoginFormComponent implements AfterViewInit { data = new LoginData(); public constructor(private toaster: ToastsManager, private router: Router, private userService: UserService) { this.data.username = 'admin'; this.data.password = 'securis'; } public login() { this.userService.login(this.data.username, this.data.password).subscribe( token => { this.router.navigateByUrl("packs"); }, errMsg => this.toaster.error(errMsg, 'Login error')); } public clear() { this.data.username = ''; this.data.password = ''; } ngAfterViewInit() { } }