Struggling with updating the parent component after routing from a child component. Through research, I've learned that ngOnInit only runs once. Any way to work around this issue? I've experimented with different lifecycle hooks, but no luck so far. Could really use some assistance! THANKS!
Here are my routes:
{
path: 'dashboard',
component: DashboardComponent,
children: [
{
// No child component visible on dashboard
path: '',
},
{ // Detail component
path: ':table/:id', //
component: DetailComponent,
},
// Additional child routes and components...
]
}
ngOnInit within Dashboard Component (parent)
ngOnInit() {
this.getSomething1(); // Populates an array
this.getSomething2(); // Populates another array
}
When a user selects an item from either array above, they're directed to the detail page for editing/deletion.
Function in child component - when an item is deleted, user is routed back to the parent component:
deleteItem(item: any) {
// Code to delete item
this._router.navigate(['dashboard']);
}
All works as expected except for the fact that the array of items isn't updated because ngOnInit only runs once. I'd like to trigger the methods getSomething1()
and getSomething2()
again when the user returns to DashboardComponent from DetailComponent.
Appreciate any guidance provided!