1

I've defined a route foo/:id/edit to use few resolvers that make service calls.

After some action on this view I want to reload data gathered from those resolvers without refreshing the whole page.

I've read here I shouldn't call resolvers manually. But maybe there's another way.

Kamil
  • 1,456
  • 4
  • 32
  • 50
  • 1
    Would you consider injecting a SharedService in the component that gets loaded on path `foo/:id/edit` and then use that service to get the data recurringly as opposed to using Resolvers? – SiddAjmera Nov 25 '18 at 10:53

1 Answers1

1

What I did was navigating to the same URL I'm on:

this.router.navigate([this.router.url]);

but in order to trigger the resolvers runGuardsAndResolvers: 'always' had to be added to route config and onSameUrlNavigation: 'reload' to app-routing.module:

@NgModule({
    imports: [
        RouterModule.forRoot(
            [
            { useHash: true, enableTracing: DEBUG_INFO_ENABLED, onSameUrlNavigation: 'reload', scrollPositionRestoration: 'disabled' }
        )
    ],

What is worth noticing is scrollPositionRestoration: 'disabled' which keeps my scroll position intact. I've read that it's available since Angular 6.1.

Instead of adding those configs above you can add refresh=1 or similar to your URL so the resolvers would get triggered out of the box.

Inspired by SO answers.

Kamil
  • 1,456
  • 4
  • 32
  • 50