@@ -25,6 +25,7 @@ import {Rejection} from "./rejectFactory";
25
25
import { ResolveContext } from "../resolve/resolveContext" ;
26
26
import { UiRouter } from "../router" ;
27
27
import { Globals } from "../globals" ;
28
+ import { UiInjector } from "../common/interface" ;
28
29
29
30
30
31
let transitionCount = 0 ;
@@ -44,6 +45,14 @@ export class Transition implements IHookRegistry {
44
45
$id : number ;
45
46
success : boolean ;
46
47
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 */
47
56
private _deferred = services . $q . defer ( ) ;
48
57
/**
49
58
* This promise is resolved or rejected based on the outcome of the Transition.
@@ -140,7 +149,8 @@ export class Transition implements IHookRegistry {
140
149
* @param targetState The target state and parameters being transitioned to (also, the transition options)
141
150
* @param router The [[UiRouter]] instance
142
151
*/
143
- constructor ( fromPath : PathNode [ ] , targetState : TargetState , private router : UiRouter ) {
152
+ constructor ( fromPath : PathNode [ ] , targetState : TargetState , router : UiRouter ) {
153
+ this . router = router ;
144
154
if ( ! targetState . valid ( ) ) {
145
155
throw new Error ( targetState . error ( ) ) ;
146
156
}
@@ -219,6 +229,26 @@ export class Transition implements IHookRegistry {
219
229
return this . _treeChanges [ pathname ] . map ( prop ( "paramValues" ) ) . reduce ( mergeR , { } ) ;
220
230
}
221
231
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
+
222
252
/**
223
253
* Gets all available resolve tokens (keys)
224
254
*
0 commit comments