如何在不刷新角度7,8的情况下重新加载整个页面? [英] How to reload whole page without refresh in angular 7,8?

查看:181
本文介绍了如何在不刷新角度7,8的情况下重新加载整个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular 8,并且希望在同一位置刷新我的组件网址,而不刷新整个页面.我正在尝试router.navigate但它对我不起作用.我尝试使用 location.reload window.location.reload ,但是它花费了太多时间,并且会刷新整个页面.下面是我的相同代码:

I am working with angular 8 and want to refresh my component on same url without refresh whole page. I am trying with router.navigate but its not working for me. I tried with location.reload and window.location.reload but it takes too much time and it refresh whole page. Below is my code for same :

this.snackBar.open('Data Updated Successfully', 'Undo', {
        duration: 5000,
      });
      this.router.navigate(['/get_customer_details/'+this.customer_details_id]);
      console.log(this.customer_details_id);
      this.ngOnInit();

推荐答案

默认情况下,Angular的 RouteReuseStrategy 为true.您需要将其更改为假.

By default RouteReuseStrategy of Angular is true. You need to cahnge it to false.

在构造函数中使用以下代码

Use the following code in your constructor

constructor(private route: ActivatedRoute, private router: Router) {
    this.router.routeReuseStrategy.shouldReuseRoute = () => false;
  }

这篇关于如何在不刷新角度7,8的情况下重新加载整个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆