added login functionality to LoginComponent
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { AccountService } from '../account.service';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { first } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
@@ -18,11 +19,16 @@ export class LoginComponent implements OnInit {
|
||||
|
||||
onLogin() {
|
||||
this.loading = true;
|
||||
if (this.form.invalid) {
|
||||
return;
|
||||
}
|
||||
console.log(this.form.value);
|
||||
|
||||
this.accountService.login(this.form.controls['username'], this.form.controls['password'])
|
||||
.pipe(first())
|
||||
.subscribe(data => {
|
||||
this.router.navigate([this.returnUrl]);
|
||||
},
|
||||
error => {
|
||||
// TODO error handling
|
||||
console.log(error);
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
constructor(private accountService: AccountService,
|
||||
|
||||
Reference in New Issue
Block a user