@@ -25,6 +25,7 @@ import {Rejection} from "./rejectFactory";
2525import { ResolveContext } from "../resolve/resolveContext" ;
2626import { UiRouter } from "../router" ;
2727import { Globals } from "../globals" ;
28+ import { UiInjector } from "../common/interface" ;
2829
2930
3031let transitionCount = 0 ;
@@ -44,6 +45,14 @@ export class Transition implements IHookRegistry {
4445 $id : number ;
4546 success : boolean ;
4647
48+ /**
49+ * A reference to the [[UiRouter]] instance
50+ *
51+ * This reference can be used to access the router services, such as the [[StateService]]
52+ */
53+ router : UiRouter ;
54+
55+ /** @hidden */
4756 private _deferred = services . $q . defer ( ) ;
4857 /**
4958 * This promise is resolved or rejected based on the outcome of the Transition.
@@ -140,7 +149,8 @@ export class Transition implements IHookRegistry {
140149 * @param targetState The target state and parameters being transitioned to (also, the transition options)
141150 * @param router The [[UiRouter]] instance
142151 */
143- constructor ( fromPath : PathNode [ ] , targetState : TargetState , private router : UiRouter ) {
152+ constructor ( fromPath : PathNode [ ] , targetState : TargetState , router : UiRouter ) {
153+ this . router = router ;
144154 if ( ! targetState . valid ( ) ) {
145155 throw new Error ( targetState . error ( ) ) ;
146156 }
@@ -219,6 +229,26 @@ export class Transition implements IHookRegistry {
219229 return this . _treeChanges [ pathname ] . map ( prop ( "paramValues" ) ) . reduce ( mergeR , { } ) ;
220230 }
221231
232+
233+ /**
234+ * Creates a [[UiInjector]] Dependency Injector
235+ *
236+ * Returns a Dependency Injector for the Transition's target state (to state).
237+ * The injector provides resolve values which the target state has access to.
238+ *
239+ * The `UiInjector` can also provide values from the native root/global injector (ng1/ng2).
240+ *
241+ * If a `state` is provided, the injector that is returned will be limited to resolve values that the provided state has access to.
242+ *
243+ * @param state Limits the resolves provided to only the resolves the provided state has access to.
244+ * @returns a [[UiInjector]]
245+ */
246+ injector ( state ?: StateOrName ) : UiInjector {
247+ let path : PathNode [ ] = this . treeChanges ( ) . to ;
248+ if ( state ) path = PathFactory . subPath ( path , node => node . state === state || node . state . name === state ) ;
249+ return new ResolveContext ( path ) . injector ( ) ;
250+ }
251+
222252 /**
223253 * Gets all available resolve tokens (keys)
224254 *
0 commit comments