我在Page B
并且我将用户路由到Page A
在Page 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 A
。Page 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]
})