0

我在Page B并且我将用户路由到Page APage B. 如何刷新Page A以便获取新数据。我编写了一个服务来获取我在Page A的构造函数中调用的数据,如下所示。

页面 A

Page A的构造函数

data: any = [];

constructor(
   private dataService: DataService,
   private route: ActivatedRoute,
 ){
   this.route.params.subscribe(val => {
     this.dataService.getData().subscribe(res => this.data = response);
  });
}

B页

Page B中,我正在执行一个按钮操作以路由到Page APage A有了这个,我期待它在执行此按钮操作时刷新。有人可以帮忙吗?

onSubmit() {
  this.router.navigateByUrl('/', {
    skipLocationChange: true
  }).then(() => {
    this.router.navigate(['page-a']);
  });
}

另外,我确实在app-routing.module.ts文件中onSameUrlNavigation设置了这个。reload

@NgModule({
  imports: [
    RouterModule.forRoot(routes, {
      preloadingStrategy: PreloadAllModules,
      onSameUrlNavigation: 'reload'
    })
  ],
  exports: [RouterModule]
})
4

2 回答 2

0

让我们试试这个:

您将在页面 A 构造函数中编写的代码移动到 ngOnInit() 中,然后检查

于 2020-03-29T20:06:15.430 回答
0

您将代码移动到ionViewDidEnter() 中,该代码写入构造函数(){/移动此代码/ }并尝试将一个页面导航到另一个页面。

于 2021-09-12T19:09:59.493 回答