I've been working on developing a login page using Angular framework. However, I'm facing an issue where I am unable to access the destination page after entering the login credentials. Below, you can find a snippet of the code from the login.component.html file:
<form *ngSwitchCase="'Login'">
<h3>Login</h3>
<label>Email:</label>
<br>
<input type="text" name="email" [(ngModel)]='email'>
<br>
<label>Password:</label>
<br>
<input type="password" name="pswd" [(ngModel)]="pswd">
<br>
<div class="foo">
<input class="btn btn-primary" type="button" value="Login" click="onClick()" >
<input class="btn btn-danger" type="button" value="Cancel" >
</div>
<button type="button" class="btn btn-info"(click)="swap()" >Not yet Registered?(Sign Up).</button>
Additionally, here is a snippet of the component.ts file:
import { Router } from '@angular/router';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
constructor(private router:Router) { }
ngOnInit(): void {
}
public val='Sign Up';
email:string;
pswd:string;
swap()
{
if(this.val=='Sign Up')
{
this.val='Login';
}
else
{
this.val='Sign Up';
}
}
onClick():any{
if(this.email=="example@email.com" && this.pswd=="theSkinnyWeirdo")
{
this.router.navigateByUrl('/list');
}
else
{
window.alert("Incorrect Email or Password!");
}
}
}
It seems that there is also an issue with the URL not changing when clicking the login button. Here are some quick suggestions for fixing this problem:
1. Ensure that the routing module is properly configured in your Angular application.
2. Check if there are any errors or console logs related to navigation events.
3. Double-check the onClick function to ensure it is correctly redirecting to the desired destination upon successful login.
By following these steps, you should be able to resolve the issue with the URL not changing after clicking the login button.