Skip to content

Instantly share code, notes, and snippets.

@svngoku
Forked from NetanelBasal/ap-6.ts
Created May 1, 2019 11:35
Show Gist options
  • Save svngoku/f94d8c7b4b981aa7df9f816bd7f62e83 to your computer and use it in GitHub Desktop.
Save svngoku/f94d8c7b4b981aa7df9f816bd7f62e83 to your computer and use it in GitHub Desktop.
@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