Home > other >  Chaining Angular resolvers
Chaining Angular resolvers

Time:09-22

I've got this basic route set up like so,

 RouterModule.forChild([
        {
          path: '',
          resolve: {
            data: DataResolver,
            stuff: StuffResolver, // <-- This needs data from DataResolver
          },
          component: DashboardComponent,
        },
      ],
    ),

And I want to resolve things inside the "StuffResolver", but in order to do that I require the data from "DataResolver" first.
I can I go about chaining or setting a "resolve order" to my resolvers so that I always have the data I need?

Thank you

CodePudding user response:

Angular Router internally uses mergeMap operator so all resolvers are executed simultaneously. (It's seems logic because there is no defined order for object properties in Javascript.)

Create one Resolver with chained operators that fetches all data in the right order.

  • Related