You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

32 lines
842 B

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)
);
}
}