# Class Transition

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.

- Defined in router/transition/transition.js:37
- Defined in router/transition/transition.js:715

#####
Index

### Constructors

constructor

### Properties

$id
_aborted
_deferred
_error
_hookBuilder
_options
_registeredHooks
_targetState
_treeChanges
globals
isActive
promise
success
transitionService
diToken

### Methods

$from
$to
_changedParams
_ignoredReason
abort
addResolvable
applyViewConfigs
createTransitionHookRegFns
dynamic
entering
error
exiting
from
getHooks
getResolveTokens
ignored
injector
is
options
originalTransition
params
paramsChanged
redirect
redirectedFrom
retained
run
targetState
to
toString
treeChanges
valid
views

##
Constructors

### constructor

- new Transition(fromPath, targetState, transitionService, globals): Transition
- `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

  - Defined in router/transition/transition.js:51

##
Properties

### $id

$id: number

- Defined in router/transition/transition.js:77

### _aborted

_aborted: boolean

- Defined in router/transition/transition.js:656

### _deferred

_deferred: Deferred<any>

- Defined in router/transition/transition.js:54

### _error

_error: any

- Defined in router/transition/transition.js:615

### _hookBuilder

_hookBuilder: HookBuilder

- Defined in router/transition/transition.js:65

### _options

_options: any

- Defined in router/transition/transition.js:73

### `Internal`_registeredHooks

_registeredHooks: {}

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

- Defined in router/transition/transition.js:63

### _targetState

_targetState: any

- Defined in router/transition/transition.js:68

### _treeChanges

_treeChanges: {
entering: any;
exiting: any;
from: any;
retained: any;
retainedWithToParams: any;
to: any;
}

- Defined in router/transition/transition.js:79

### globals

globals: any

- Defined in router/transition/transition.js:52

### isActive

isActive: (() => boolean)

Checks if this transition is currently active/running.

- Defined in router/transition/transition.js:67

### promise

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

- Defined in router/transition/transition.js:61

### success

success: boolean

- Defined in router/transition/transition.js:607
- Defined in router/transition/transition.js:613

### transitionService

transitionService: TransitionService

- Defined in router/transition/transition.js:53

### `Static` diToken

diToken: typeof Transition

- Defined in router/transition/transition.js:715

##
Methods

### $from

- $from(): any
- `Internal`

  #### Returns any

  the internal from [State] object

  - Defined in router/transition/transition.js:119

### $to

- $to(): any
- `Internal`

  #### Returns any

  the internal to [State] object

  - Defined in router/transition/transition.js:126

### _changedParams

- _changedParams(): any
- `Internal`

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

  #### Returns any

  - Defined in router/transition/transition.js:513

### _ignoredReason

- _ignoredReason(): "SameAsPending" | "SameAsCurrent"

- #### Returns "SameAsPending" | "SameAsCurrent"

  - Defined in router/transition/transition.js:563

### abort

- abort(): void

- Aborts this transition

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

  #### Returns void

  - Defined in router/transition/transition.js:653

### addResolvable

- addResolvable(resolvable, state): 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.

  #### Example:

      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

  - Defined in router/transition/transition.js:326

### applyViewConfigs

- applyViewConfigs(): void

- #### Returns void

  - Defined in router/transition/transition.js:107

### createTransitionHookRegFns

- createTransitionHookRegFns(): void

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

  #### Returns void

  - Defined in router/transition/transition.js:96

### dynamic

- dynamic(): any

- 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

  - Defined in router/transition/transition.js:546

### entering

- entering(): any

- Gets the states being entered.

  #### Returns any

  an array of states that will be entered during this transition.

  - Defined in router/transition/transition.js:405

### error

- error(): any

- 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.

  - Defined in router/transition/transition.js:667

### exiting

- exiting(): any

- Gets the states being exited.

  #### Returns any

  an array of states that will be exited during this transition.

  - Defined in router/transition/transition.js:413

### from

- from(): any

- 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").

  - Defined in router/transition/transition.js:136

### getHooks

- getHooks(hookName): any

- #### Parameters

  - hookName: any

  #### Returns any

  - Defined in router/transition/transition.js:103

### getResolveTokens

- getResolveTokens(pathname?): any

- 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.

  #### Example:

  This example logs all resolve values

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

  #### Example:

  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)

  - Defined in router/transition/transition.js:294

### ignored

- ignored(): boolean

- 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.

  - Defined in router/transition/transition.js:559

### injector

- injector(state, pathName?): UIInjectorImpl

- 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).

  #### Example:

      .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.

  #### Example:

      .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`.

  #### Example:

      .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.

  #### Example:

      .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]]

  - Defined in router/transition/transition.js:253

### is

- is(compare): any

- Determines whether two transitions are equivalent.

  #### Parameters

  - compare: any

  #### Returns any

  #### Deprecated

  - Defined in router/transition/transition.js:163

### options

- options(): any

- Get the transition options

  #### Returns any

  the options for this Transition.

  - Defined in router/transition/transition.js:397

### originalTransition

- originalTransition(): any

- 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.

  #### Example:

      // 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

  - Defined in router/transition/transition.js:388

### params

- params(pathname?): any

- #### Parameters

  - pathname: string = "to"

  #### Returns any

  - Defined in router/transition/transition.js:173

### paramsChanged

- paramsChanged(): any

- #### Returns any

  - Defined in router/transition/transition.js:178

### redirect

- redirect(targetState): Transition
- `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.

  - Defined in router/transition/transition.js:457

### redirectedFrom

- redirectedFrom(): any

- Gets the transition from which this transition was redirected.

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

  #### Example:

      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

  - Defined in router/transition/transition.js:359

### retained

- retained(): any

- 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

  - Defined in router/transition/transition.js:424

### run

- run(): QPromise<any>
- `Internal`

  Runs the transition

  This method is generally called from the [[StateService.transitionTo]]

  #### Returns QPromise<any>

  a promise for a successful transition.

  - Defined in router/transition/transition.js:600

### targetState

- targetState(): any

- 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

  - Defined in router/transition/transition.js:156

### to

- to(): any

- 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").

  - Defined in router/transition/transition.js:146

### toString

- toString(): string

- A string representation of the Transition

  #### Returns string

  A string representation of the Transition

  - Defined in router/transition/transition.js:693

### treeChanges

- treeChanges(pathname): any

- #### Parameters

  - pathname: any

  #### Returns any

  - Defined in router/transition/transition.js:444

### valid

- valid(): boolean

- Checks if the Transition is valid

  #### Returns boolean

  true if the Transition is valid

  - Defined in router/transition/transition.js:644

### views

- views(pathname?, state): any

- 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 `ViewConfig`s for a single state in the path

  #### Returns any

  a list of ViewConfig objects for the given path.

  - Defined in router/transition/transition.js:439