import { Component } from '@angular/core'; import { FormGroup, FormBuilder, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { AuthService } from '../../services/auth-service'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.less'] }) export class LoginComponent { username: string = ''; password: string = ''; constructor(private fb:FormBuilder, private authService: AuthService, private router: Router) {} login(): void { this.authService.login(this.username, this.password).subscribe( (response) => { if (response.token) { localStorage.setItem('token', response.token); this.router.navigate(['/profile']); } }, (error) => console.error(error) ); } }