我正在使用Angular创建一个登录页面,但在输入登录信息后无法访问目标页面,以下是login.component.html文件的代码片段。
<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>
下面是component.ts文件的代码片段。
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=="[email protected]" && this.pswd=="theSkinnyWeirdo")
{
this.router.navigateByUrl('/list');
}
else
{
window.alert("Incorrect Email or Password!");
}
}
}````
Also the url doesn't change when I click the login button.
Please provide a quick fix for this.
请在下面找到解决方案:-