Represents a transition between two states.

When navigating to a state, we are transitioning from the current state to the new state.

This object contains all contextual information about the to/from states, parameters, resolves. It has information about all states being entered and exited as a result of the transition.

Constructors

  • Internal

    Creates a new Transition object.

    If the target state is not valid, an error is thrown.

    Parameters

    • fromPath: any

      The path of [[PathNode]]s from which the transition is leaving. The last node in the fromPath encapsulates the "from state".

    • targetState: any

      The target state and parameters being transitioned to (also, the transition options)

    • transitionService: TransitionService

      The [[TransitionService]] instance

    • globals: any

    Returns Transition

Properties

$id: number
_aborted: boolean
_deferred: Deferred<any>
_error: any
_hookBuilder: HookBuilder
_options: any
_registeredHooks: {}

Holds the hook registration functions such as those passed to Transition.onStart()

_targetState: any
_treeChanges: {
    entering: any;
    exiting: any;
    from: any;
    retained: any;
    retainedWithToParams: any;
    to: any;
}
globals: any
isActive: (() => boolean)

Checks if this transition is currently active/running.

promise: QPromise<any>

This promise is resolved or rejected based on the outcome of the Transition.

When the transition is successful, the promise is resolved When the transition is unsuccessful, the promise is rejected with the [[Rejection]] or javascript error

success: boolean
transitionService: TransitionService
diToken: typeof Transition

Methods

  • Internal

    If a transition doesn't exit/enter any states, returns any [[Param]] whose value changed

    Returns any

  • Aborts this transition

    Imperative API to abort a Transition. This only applies to Transitions that are not yet complete.

    Returns void

  • Dynamically adds a new [[Resolvable]] (i.e., [[StateDeclaration.resolve]]) to this transition.

    Allows a transition hook to dynamically add a Resolvable to this Transition.

    Use the [[Transition.injector]] to retrieve the resolved data in subsequent hooks ([[UIInjector.get]]).

    If a state argument is provided, the Resolvable is processed when that state is being entered. If no state is provided then the root state is used. If the given state has already been entered, the Resolvable is processed when any child state is entered. If no child states will be entered, the Resolvable is processed during the onFinish phase of the Transition.

    The state argument also scopes the resolved data. The resolved data is available from the injector for that state and any children states.

    transitionService.onBefore({}, transition => {
    transition.addResolvable({
    token: 'myResolve',
    deps: ['MyService'],
    resolveFn: myService => myService.getData()
    });
    });

    Parameters

    • resolvable: any

      a [[ResolvableLiteral]] object (or a [[Resolvable]])

    • state: any

      the state in the "to path" which should receive the new resolve (otherwise, the root state)

    Returns void

  • Creates the transition-level hook registration functions (which can then be used to register hooks)

    Returns void

  • Returns true if the transition is dynamic.

    A transition is dynamic if no states are entered nor exited, but at least one dynamic parameter has changed.

    Returns any

    true if the Transition is dynamic

  • The Transition error reason.

    If the transition is invalid (and could not be run), returns the reason the transition is invalid. If the transition was valid and ran, but was not successful, returns the reason the transition failed.

    Returns any

    a transition rejection explaining why the transition is invalid, or the reason the transition failed.

  • Returns the "from state"

    Returns the state that the transition is coming from.

    Returns any

    The state declaration object for the Transition's ("from state").

  • Gets all available resolve tokens (keys)

    This method can be used in conjunction with [[injector]] to inspect the resolve values available to the Transition.

    This returns all the tokens defined on [[StateDeclaration.resolve]] blocks, for the states in the Transition's [[TreeChanges.to]] path.

    This example logs all resolve values

    let tokens = trans.getResolveTokens();
    tokens.forEach(token => console.log(token + " = " + trans.injector().get(token)));

    This example creates promises for each resolve value. This triggers fetches of resolves (if any have not yet been fetched). When all promises have all settled, it logs the resolve values.

    let tokens = trans.getResolveTokens();
    let promise = tokens.map(token => trans.injector().getAsync(token));
    Promise.all(promises).then(values => console.log("Resolved values: " + values));

    Note: Angular 1 users whould use $q.all()

    Parameters

    • pathname: string = "to"

      resolve context's path name (e.g., to or from)

    Returns any

    an array of resolve tokens (keys)

  • Returns true if the transition is ignored.

    A transition is ignored if no states are entered nor exited, and no parameter values have changed.

    Returns boolean

    true if the Transition is ignored.

  • Creates a [[UIInjector]] Dependency Injector

    Returns a Dependency Injector for the Transition's target state (to state). The injector provides resolve values which the target state has access to.

    The UIInjector can also provide values from the native root/global injector (ng1/ng2).

    .onEnter({ entering: 'myState' }, trans => {
    var myResolveValue = trans.injector().get('myResolve');
    // Inject a global service from the global/native injector (if it exists)
    var MyService = trans.injector().get('MyService');
    })

    In some cases (such as onBefore), you may need access to some resolve data but it has not yet been fetched. You can use [[UIInjector.getAsync]] to get a promise for the data.

    .onBefore({}, trans => {
    return trans.injector().getAsync('myResolve').then(myResolveValue =>
    return myResolveValue !== 'ABORT';
    });
    });

    If a state is provided, the injector that is returned will be limited to resolve values that the provided state has access to. This can be useful if both a parent state foo and a child state foo.bar have both defined a resolve such as data.

    .onEnter({ to: 'foo.bar' }, trans => {
    // returns result of `foo` state's `myResolve` resolve
    // even though `foo.bar` also has a `myResolve` resolve
    var fooData = trans.injector('foo').get('myResolve');
    });

    If you need resolve data from the exiting states, pass 'from' as pathName. The resolve data from the from path will be returned.

    .onExit({ exiting: 'foo.bar' }, trans => {
    // Gets the resolve value of `myResolve` from the state being exited
    var fooData = trans.injector(null, 'from').get('myResolve');
    });

    Parameters

    • state: any

      Limits the resolves provided to only the resolves the provided state has access to.

    • pathName: string = "to"

      Default: 'to': Chooses the path for which to create the injector. Use this to access resolves for exiting states.

    Returns UIInjectorImpl

    a [[UIInjector]]

  • Gets the original transition in a redirect chain

    A transition might belong to a long chain of multiple redirects. This method walks the [[redirectedFrom]] chain back to the original (first) transition in the chain.

    // states
    registry.register({ name: 'A', redirectTo: 'B' });
    registry.register({ name: 'B', redirectTo: 'C' });
    registry.register({ name: 'C', redirectTo: 'D' });
    registry.register({ name: 'D' });

    let transitionA = $state.go('A').transition

    $transitions.onSuccess({ to: 'D' }, (trans) => {
    trans.to().name === 'D'; // true
    trans.redirectedFrom().to().name === 'C'; // true
    trans.originalTransition() === transitionA; // true
    trans.originalTransition().to().name === 'A'; // true
    });

    Returns any

    The original Transition that started a redirect chain

  • Internal

    Creates a new transition that is a redirection of the current one.

    This transition can be returned from a [[TransitionService]] hook to redirect a transition to a new state and/or set of parameters.

    Parameters

    • targetState: any

    Returns Transition

    Returns a new [[Transition]] instance.

  • Gets the transition from which this transition was redirected.

    If the current transition is a redirect, this method returns the transition that was redirected.

    let transitionA = $state.go('A').transition
    transitionA.onStart({}, () => $state.target('B'));
    $transitions.onSuccess({ to: 'B' }, (trans) => {
    trans.to().name === 'B'; // true
    trans.redirectedFrom() === transitionA; // true
    });

    Returns any

    The previous Transition, or null if this Transition is not the result of a redirection

  • Gets the states being retained.

    Returns any

    an array of states that are already entered from a previous Transition, that will not be exited during this Transition

  • Gets the Target State

    A transition's [[TargetState]] encapsulates the [[to]] state, the [[params]], and the [[options]] as a single object.

    Returns any

    the [[TargetState]] of this Transition

  • Returns the "to state"

    Returns the state that the transition is going to.

    Returns any

    The state declaration object for the Transition's target state ("to state").

  • Get the [[ViewConfig]]s associated with this Transition

    Each state can define one or more views (template/controller), which are encapsulated as ViewConfig objects. This method fetches the ViewConfigs for a given path in the Transition (e.g., "to" or "entering").

    Parameters

    • pathname: string = "entering"

      the name of the path to fetch views for: ('to', 'from', 'entering', 'exiting', 'retained')

    • state: any

      If provided, only returns the ViewConfigs for a single state in the path

    Returns any

    a list of ViewConfig objects for the given path.