【发布时间】:2019-04-21 18:19:52
【问题描述】:
在登录仪表板加载到该页面后,我有一个 Angular 页面。我在应用程序组件中有标题,并且从浏览器的本地存储中加载了一些详细信息。但是在路由到仪表板之后,标题图标没有加载,因为我已经为标题图标设置了一个 ngIf 条件,如下所示
<button
*ngIf="isLoggedIn == 'true'"
mat-icon-button
(click)="snav.toggle()"
>
<mat-icon style="color:white;">menu</mat-icon>
</button>
如果本地存储 LoggedIn 值为 true,则仅此按钮可见。
但在我的情况下,在我的登录组件中点击登录按钮后,它会调用一个服务,并从那里设置本地存储值。
if (res1["retFlag"] === "0") {
this.http
.post("http://213.136.79.138:8080/gdp/login", obj, httpOptions)
.subscribe(
res => {
console.log(res);
// console.log('userid' + '' + res['userid']);
// tslint:disable-next-line:no-string-literal
if (res["returnFlag"] === 0) {
// tslint:disable-next-line:no-string-literal
const userid = res["loginEmployeeId"];
const username = res["username"];
localStorage.setItem("userid", userid);
localStorage.setItem("isLoggedIn", "true");
localStorage.setItem("username", username);
console.log(username);
// console.log('signed in log val:' + localStorage.getItem('isLoggedIn'));
//window.location.href = "./dashboard";
//this.router.navigate(["dashboard"]);
// var url = '@Url.Action("Action", "/dashboard")';
// window.location.href = url;
this.router.navigateByUrl("dashboard");
// this.router.navigate(['dashboard']);
} else {
alert("Username or Password Incorrect");
}
},
err => {
// this.loading = false;
console.log(err);
}
);
} else {
alert("UserName Not Available");
}
},
err => {
// this.loading = false;
console.log(err);
}
);
但问题是重定向后没有刷新标题。
如果我使用 window.location.href = "dashboard" 在本地开发服务器中工作正常。但是当托管到tomcat时它不起作用。有人可以提出解决这个问题的方法吗
【问题讨论】: