如何在Angular中刷新组件 [英] How to Refresh a Component in Angular
本文介绍了如何在Angular中刷新组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从事Angular项目。我正在为组件的刷新动作而苦苦挣扎。
我想在单击按钮时刷新路由器的组件。
单击组件/路由器时需要刷新按钮。
我尝试了 window.location.reload()
和 location.reload()
这两个都不适合我的需要。
I am working on an Angular project. I'm struggling with refresh action in a component.
I would like to refresh the router's components on button click.
I have refresh button when I click on it the component/router need to be refresh.
I tried window.location.reload()
and location.reload()
these two are not suitable for my need. Please help if anyone aware of it.
推荐答案
经过一番研究并按如下所示修改了我的代码,该脚本对我有用。我刚刚添加了条件:
After some research and modifying my code as below, the script worked for me. I just added the condition:
this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
this.router.navigate(['Your actualComponent']);
});
这篇关于如何在Angular中刷新组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文