ResolvePolicy | @uirouter/angular
Options
Menu

Interface ResolvePolicy

Defines how a resolve is processed during a transition

This object is the StateDeclaration.resolvePolicy property.

Example:

// Fetched when the resolve's state is being entered.
// Wait for the promise to resolve.
var policy1 = { when: "LAZY", async: "WAIT" }

// Fetched when the Transition is starting.
// Do not wait for the returned promise to resolve.
// Inject the raw promise/value
var policy2 = { when: "EAGER", async: "NOWAIT" }

The policy for a given Resolvable is merged from three sources (highest priority first):

  • 1) Individual resolve definition
  • 2) State definition
  • 3) Global default

Example:

// Wait for an Observable to emit one item.
// Since `wait` is not specified, it uses the `wait`
// policy defined on the state, or the global default
// if no `wait` policy is defined on the state
var myResolvablePolicy = { async: "RXWAIT" }

Hierarchy

  • ResolvePolicy

Index

Properties

Properties

async: PolicyAsync

Determines the unwrapping behavior of asynchronous resolve values.

Determines the unwrapping behavior of asynchronous resolve values.

  • WAIT (default)
    • If a promise is returned from the resolveFn, wait for the promise before proceeding
    • The unwrapped value from the promise
  • NOWAIT
    • If a promise is returned from the resolve, do not wait for the promise.
    • Any other value returned is wrapped in a promise.
    • The promise will not be unwrapped.
    • The promise itself will be provided when the resolve is injected or bound elsewhere.
  • RXWAIT
    • When an Observable is returned from the resolveFn, wait until the Observable emits at least one item.
    • The Observable item will not be unwrapped.
    • The Observable stream itself will be provided when the resolve is injected or bound elsewhere.

Example:

The Transition will not wait for the resolve promise(s) from main to settle before continuing. Resolves for main will be provided to components wrapped in a Promise.

The Transition will wait for the main.home resolve promises. Resolved values will be unwrapped before being provided to components.

var mainState = {
  name: 'main',
  resolve: mainResolves, // defined elsewhere
  resolvePolicy: { async: 'NOWAIT' },
}
var homeState = {
  name: 'main.home',
  resolve: homeResolves, // defined elsewhere
  resolvePolicy: { async: 'WAIT' }, // default
}
when: PolicyWhen

Defines when a Resolvable is resolved (fetched) during a transition

Defines when a Resolvable is resolved (fetched) during a transition

  • LAZY (default)
    • Resolved as the resolve's state is being entered
  • EAGER
    • Resolved as the transition is starting

Example:

Resolves for main and main.home are fetched when each state is entered. All of main resolves are processed before fetching main.home resolves.

var state = {
  name: 'main',
  resolve: mainResolves, // defined elsewhere
  resolvePolicy: { when: 'LAZY' }, // default
}

var state = {
  name: 'main.home',
  resolve: homeResolves, // defined elsewhere
  resolvePolicy: { when: 'LAZY' }, // default
}

Example:

Resolves for main and main.home are fetched at the same time when the transition starts. This happens earlier in the lifecycle than when states are entered. All of the main and main.home resolves are fetched as soon as possible.

var mainState = {
  name: 'main',
  resolve: mainResolves, // defined elsewhere
  resolvePolicy: { when: 'EAGER' },
}

var homeState = {
  name: 'main.home',
  resolve: homeResolves, // defined elsewhere
  resolvePolicy: { when: 'EAGER' },
}

Generated using TypeDoc