【问题标题】:How to reload whole page without refresh in angular 7,8?如何在不刷新角度 7,8 的情况下重新加载整个页面?
【发布时间】:2019-12-11 00:04:58
【问题描述】:

我正在使用 Angular 8 并希望在同一位置上刷新我的组件 url 不刷新整个页面。我正在尝试使用 router.navigate 但 它不适合我。我试过location.reloadwindow.location.reload 但是它需要太多时间并且它会刷新 整个页面。下面是我的代码:

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 refresh reload


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2016-09-04
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 2011-11-02
      • 2013-08-20
      相关资源
      最近更新 更多