@@ -276,13 +276,55 @@ export class Transition implements IHookRegistry {
276276 *
277277 * The `UIInjector` can also provide values from the native root/global injector (ng1/ng2).
278278 *
279+ * #### Example:
280+ * ```js
281+ * .onEnter({ entering: 'myState' }, trans => {
282+ * var myResolveValue = trans.injector().get('myResolve');
283+ * // Inject a global service from the global/native injector (if it exists)
284+ * var MyService = trans.injector().get('MyService');
285+ * })
286+ * ```
287+ *
288+ * In some cases (such as `onBefore`), you may need access to some resolve data but it has not yet been fetched.
289+ * You can use [[UIInjector.getAsync]] to get a promise for the data.
290+ * #### Example:
291+ * ```js
292+ * .onBefore({}, trans => {
293+ * return trans.injector().getAsync('myResolve').then(myResolveValue =>
294+ * return myResolveValue !== 'ABORT';
295+ * });
296+ * });
297+ * ```
298+ *
279299 * If a `state` is provided, the injector that is returned will be limited to resolve values that the provided state has access to.
300+ * This can be useful if both a parent state `foo` and a child state `foo.bar` have both defined a resolve such as `data`.
301+ * #### Example:
302+ * ```js
303+ * .onEnter({ to: 'foo.bar' }, trans => {
304+ * // returns result of `foo` state's `data` resolve
305+ * // even though `foo.bar` also has a `data` resolve
306+ * var fooData = trans.injector('foo').get('data');
307+ * });
308+ * ```
309+ *
310+ * If you need resolve data from the exiting states, pass `'from'` as `pathName`.
311+ * The resolve data from the `from` path will be returned.
312+ * #### Example:
313+ * ```js
314+ * .onExit({ exiting: 'foo.bar' }, trans => {
315+ * // Gets the resolve value of `data` from the exiting state.
316+ * var fooData = trans.injector(null, 'foo.bar').get('data');
317+ * });
318+ * ```
319+ *
280320 *
281321 * @param state Limits the resolves provided to only the resolves the provided state has access to.
322+ * @param pathName Default: `'to'`: Chooses the path for which to create the injector. Use this to access resolves for `exiting` states.
323+ *
282324 * @returns a [[UIInjector]]
283325 */
284- injector ( state ?: StateOrName ) : UIInjector {
285- let path : PathNode [ ] = this . _treeChanges . to ;
326+ injector ( state ?: StateOrName , pathName = "to" ) : UIInjector {
327+ let path : PathNode [ ] = this . _treeChanges [ pathName ] ;
286328 if ( state ) path = PathFactory . subPath ( path , node => node . state === state || node . state . name === state ) ;
287329 return new ResolveContext ( path ) . injector ( ) ;
288330 }
0 commit comments