-
-
Save svngoku/f94d8c7b4b981aa7df9f816bd7f62e83 to your computer and use it in GitHub Desktop.
This file contains 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
@Component({ | |
templateUrl: './login-page.component.html' | |
}) | |
export class LoginPageComponent { | |
loginForm = new FormGroup({ | |
email: new FormControl('', Validators.required), | |
password: new FormControl('', Validators.required) | |
}); | |
error: string | null = null; | |
constructor(private authService: AuthService, | |
private router: Router, | |
private toastr: ToastrService) {} | |
submit() { | |
this.error = null; | |
if ( this.loginForm.valid ) { | |
this.authService.login(this.loginForm.value).subscribe({ | |
next: ({ name }) => { | |
this.toastr.success(`Welcome ${name}`); | |
this.router.navigateByUrl('/'); | |
}, | |
error: (error) => { | |
this.error = error.error.errorMsg; | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment