How to reload whole page without refresh in angular 7,8?

邮差的信 提交于 2020-12-12 01:59:42

问题


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();

回答1:


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;
  }


来源:https://stackoverflow.com/questions/57325155/how-to-reload-whole-page-without-refresh-in-angular-7-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!