【发布时间】:2023-01-25 20:09:20
【问题描述】:
我正在使用 Angular 创建一个登录表单。当我登录系统时,它将在重定向到另一个页面时成功登录,它需要显示主页详细信息,但它会同时显示登录和主页详细信息。我试过了我附在下面。
email: string = '';
password: string = '';
isLogin: boolean = true;
erroMessage: string = "";
constructor(private router: Router,private http: HttpClient) {}
login() {
console.log(this.email);
console.log(this.password);
let bodyData = {
email: this.email,
password: this.password,
};
this.http.post("http://localhost:9002/user/login", bodyData).subscribe( (resultData: any) => {
console.log(resultData);
if (resultData.status)
{
alert("Sucess");
this.router.navigate(['/home']);
this.isLogin = false;
}
else
{
alert("Incorrect Email or Password");
console.log("Errror login");
}
});
}
}
航线
常量路线:路线= [
{
path: 'login',
component: LoginComponent
},
{
path: 'home',
component: HomeComponent,
}
];
【问题讨论】:
-
请包括完整的代码示例来演示错误
标签: angular