Sharing Top Content from the Angular-sphere.

Angular Route Resolvers

  • To load those resources before page display you need to strap your route with a resolve parameter that references a special injectable class called resolver.
  • You can add a resolver to your Angular application the same way as you would add a regular service.
  • Resolvers are classes that implement the resolve interface and have a resolve method which gets executed when the route is activated.
  • The router expects the resolver to return either an Observable or a Promise.
  • The route using the resolver looks similar to the following:

    I stripped away a lot of methods from the following service so that you don’t have to scan a lot of code to figure out what is happening.

Let’s see Angular route resolvers in action.
You are creating an Angular Typescript application. You have created a few services for it that contain a couple of rest calls wrapped in promises. Now you are setting up routes and you want to load certain resources before the page displays.

@notMiloBejda: @angular Route Resolvers are awesome!Thanx 4 the photo.@epicantus
#angularjs #angular #FrontEnd #angular4 #angular2🤣

Let’s see Angular route resolvers in action.

You are creating an Angular Typescript application. You have created a few services for it that contain a couple of rest calls wrapped in promises. Now you are setting up routes and you want to load certain resources before the page displays.

To load those resources before page display you need to strap your route with a resolve parameter that references a special injectable class called resolver. You can add a resolver to your Angular application the same way as you would add a regular service.

Resolvers are classes that implement the resolve interface and have a resolve method which gets executed when the route is activated. The router expects the resolver to return either an Observable or a Promise. If the returning variable is an Observable the router stops the route navigation and listens for the observable to emit a ‘complete’ event before resuming navigation again. If the returning variable is a Promise then the router waits for the Promise to resolve.

A resolver looks similar to the following:

My resolver class has some extra fluff in it, but don’t worry, I added comments to help break things down.

The route using the resolver looks similar to the following:

I stripped away a lot of methods from the following service so that you don’t have to scan a lot of code to figure out what is happening. It should get the point across:

Angular Route Resolvers

Comments are closed, but trackbacks and pingbacks are open.