Last active
March 28, 2019 15:28
-
-
Save 4skinSkywalker/8d5e24002845fbc5fa3ad271d1070310 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, OnInit } from '@angular/core'; | |
| import { AuthService } from '../services/auth.service'; | |
| import { Router } from '@angular/router' | |
| import { UnauthError } from '../common/unauth-error' | |
| import { AppError } from '../common/app-error' | |
| @Component({ | |
| selector: 'app-login', | |
| templateUrl: './login.component.html', | |
| styleUrls: ['./login.component.css'] | |
| }) | |
| export class LoginComponent implements OnInit { | |
| isInvalid: boolean = false | |
| constructor( | |
| private authService: AuthService, | |
| private router: Router) { } | |
| ngOnInit() { | |
| } | |
| submit(f) { | |
| const credentials = f.value | |
| this.authService.login(credentials) | |
| .subscribe( | |
| result => { | |
| this.router.navigate(['']) | |
| }, | |
| (error: AppError) => { // look here | |
| if (error instanceof UnauthError) { | |
| return this.isInvalid = true | |
| } | |
| } | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment