I'm on Page B
and I route user to Page A
when an action is performed in Page B
. How do I refresh the Page A
so that I can get fetch the new data. I wrote a service to fetch data which I am calling in Page A
's constructor like below.
Page A
Page A
's constructor
data: any = [];
constructor(
private dataService: DataService,
private route: ActivatedRoute,
){
this.route.params.subscribe(val => {
this.dataService.getData().subscribe(res => this.data = response);
});
}
Page B
In Page B
, I'm performing a button action to route to Page A
. With this, I was expecting it to refresh the Page A
whenever this button action is performed. Could anyone please help?
onSubmit() {
this.router.navigateByUrl('/', {
skipLocationChange: true
}).then(() => {
this.router.navigate(['page-a']);
});
}
Also, I do have this onSameUrlNavigation
set to reload
in the app-routing.module.ts file.
@NgModule({
imports: [
RouterModule.forRoot(routes, {
preloadingStrategy: PreloadAllModules,
onSameUrlNavigation: 'reload'
})
],
exports: [RouterModule]
})
Let's try this:
You move the code that you wrote in the page A constructor into ngOnInit() and then check
你将你的代码移动到ionViewDidEnter() 中,它被写入到构造函数(){/ Move this code/ }并尝试将一个页面导航到另一个页面。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.