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