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.
38 lines
888 B
38 lines
888 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 {
|
|
form:FormGroup;
|
|
|
|
constructor(private fb:FormBuilder,
|
|
private authService: AuthService,
|
|
private router: Router)
|
|
{
|
|
|
|
this.form = this.fb.group({
|
|
email: ['',Validators.required],
|
|
password: ['',Validators.required]
|
|
});
|
|
}
|
|
|
|
login() {
|
|
const val = this.form.value;
|
|
|
|
if (val.email && val.password) {
|
|
this.authService.login(val.email, val.password)
|
|
.subscribe(
|
|
() => {
|
|
console.log("User is logged in");
|
|
this.router.navigateByUrl('/');
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|