代码之家  ›  专栏  ›  技术社区  ›  user2024080

如何在访问主页时重新加载和清除所有捕获的数据?

  •  0
  • user2024080  · 技术社区  · 8 年前

    在我的应用程序中,存在多个页面。用户可以从第一页转到最后一页填写表格。由于一种形式依赖于其他形式,所以我也将这些值保存在共享服务对象中。

    现在,当用户单击返回主页时,所有服务对象值和表单都需要重置为默认值或null。我怎样才能做到这一点?

    我想办法 window.location.reload() -但这会刷新整个应用程序。正确答案是什么 angular 方法

    this.router.navigate([''], 'forcetoreload') -还是别的什么?

    有人帮我吗?

    1 回复  |  直到 8 年前
        1
  •  0
  •   Sajeetharan    8 年前

    你可以使用路由器。naviagate并调用您的服务方法来清除存储的值。

    你应该有一个方法来清除这些值

    clearValues():void {
       this.storageValues = [];
    }
    

    然后在组件中,

    this.router.navigate(['/home');
    this.myService.clearValues();