import { Route } from '@angular/compiler/src/core'; import { Component, OnInit } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { Observable } from 'rxjs'; import { Login } from 'src/app/models/login'; import { User } from 'src/app/models/user'; import { UserService } from 'src/app/services/user.service'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.css'] }) export class LoginComponent implements OnInit { username = new FormControl(); password = new FormControl(); responseMessage : string = ""; temp : Observable; // temp : User; temps : Observable; userList : Observable; constructor(private _userService : UserService, private router : Router) {} userLogin() { // alert(this.username.value+" | "+this.password.value); let user : Login = { userfirstname: this.username.value, userpassword: this.password.value } this.temp = this._userService.findUserByUsername(this.username.value); this.temp.subscribe(v => { if(v.userpassword == this.password.value) this.responseMessage = "Login success !!"; else this.responseMessage = "Password Incorrect."; }); if(this.responseMessage == "Login success !!") { this.temp.subscribe(v => this._userService.currentUser = v); this.router.navigateByUrl('/home'); } else alert(this.responseMessage); } ngOnInit(): void { } }