You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 lines
1.4 KiB

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { User } from 'src/app/model/user.model';
import { AppserviceService } from 'src/app/service/appservice.service';
import { UserServiceService } from 'src/app/service/user-service.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
user:User=new User();
loginForm:FormGroup;
msg:string;
constructor(private route:Router,private userService:UserServiceService,private appService:AppserviceService) {
this.msg="";
}
ngOnInit(): void {
this.loginForm=new FormGroup(
{
username:new FormControl('',Validators.required),
password:new FormControl('',Validators.required),
}
);
}
onloginFormSubmit(){
console.log(this.loginForm.value.username);
this.userService.getUser(this.loginForm.value).subscribe(data=>{
window.localStorage.setItem('username',this.loginForm.value.username);
window.localStorage.setItem('isLoggedIn','true');
this.appService.activate.next(true);
//this.authService.isAuthenticated();
this.route.navigateByUrl('/home');
},(err:any)=>{
console.log(err)
this.msg="Invalid Credentials";
});
}}