更新时间:2023-11-26 16:37:04
在以下***中找到了解决方案:
The solution was found in the following ***:
这使我在Internet Explorer中对其进行了测试,该工作正常,但无法在Chrome中正常工作
This led me to test it in Internet Explorer, which worked OK (it was not working in Chrome)
原来,执行以下行时,整个页面都在刷新:
It turned out that the entire page was refreshing when the following line was executed:
this.router.navigate([this.returnUrl]);
这是导致用户服务重新加载的原因,因为按钮上没有 type 类型,Chrome的默认操作是将按钮单击视为提交.
Which was causing the user service to reload again, because without a type on the button, Chrome's default action was to treat the button click as a submit.
解决方法是将标记 type ="button" 添加到html中的登录按钮
The fix was to add the tag type="button" to the login button in the html
<button type="button" class="btn btn-primary"(click)="validateUser(username, password)">Login</button>
它现在可以在所有浏览器中使用.
It now works in all browsers.