UNPKG

mean-guide-frontend

Version:

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1.

33 lines (28 loc) 815 B
import { Component, OnInit, OnDestroy } from '@angular/core'; import { NgForm } from '@angular/forms'; import { AuthService } from '../auth.service'; import { Subscription } from 'rxjs'; @Component({ templateUrl: './login.component.html', styleUrls: ['./login.component.css'], }) export class LoginComponent implements OnInit, OnDestroy { constructor(public authService: AuthService) {} isLoading = false; private authStatusSub: Subscription; ngOnInit() { this.authStatusSub = this.authService .getAuthStatusListener() .subscribe((status) => (this.isLoading = false)); } onLogin(form: NgForm) { if (form.invalid) { return; } this.isLoading = true; this.authService.login({ ...form.value }); } ngOnDestroy() { this.authStatusSub.unsubscribe(); } }