source: Farmatiko/ClientApp/src/app/login/login.component.ts@ 993189e

Last change on this file since 993189e was 993189e, checked in by Mile Jankuloski <mile.jankuloski@…>, 3 years ago

Auth guards and services, refactored components

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import { Component, OnInit } from '@angular/core';
2import { FormGroup, FormControl, Validators } from '@angular/forms';
3import { Router, ActivatedRoute } from '@angular/router';
4import { first } from 'rxjs/operators';
5import { AuthService } from '../shared/auth.service';
6
7@Component({
8 selector: 'app-login',
9 templateUrl: './login.component.html',
10 styleUrls: ['./login.component.css']
11})
12export class LoginComponent implements OnInit {
13 loginForm: FormGroup;
14 email: string;
15 passwd: string;
16 errorMessage: string;
17
18 constructor(private authService: AuthService,private router: Router, private route: ActivatedRoute) {
19 this.loginForm = new FormGroup({
20 email: new FormControl('', [Validators.required, Validators.email]),
21 password: new FormControl('', [Validators.required])
22 });
23 }
24
25 ngOnInit(): void {
26 }
27
28 loginPharmacyHead() {
29 this.authService.login(this.email,this.passwd)
30 .pipe(first())
31 .subscribe((data) => {
32 if(data) {
33 this.router.navigate(['/dashboard']);
34 }},
35 (err: any) => {
36 this.errorMessage = err.toString();
37 });
38 this.loginForm.reset();
39 }
40}
Note: See TracBrowser for help on using the repository browser.