@@ -205,7 +205,7 @@ export interface TransitionHookFn {
205
205
*
206
206
* - [[IHookRegistry.onExit]]
207
207
* - [[IHookRegistry.onRetain]]
208
- * - [[IHookRegistry.onExit ]]
208
+ * - [[IHookRegistry.onEnter ]]
209
209
*/
210
210
export interface TransitionStateHookFn {
211
211
( transition : Transition , state : State ) : HookResult
@@ -291,12 +291,12 @@ export interface IHookRegistry {
291
291
*
292
292
* This example redirects any transition from 'home' to 'home.dashboard'. This is commonly referred to as a
293
293
* "default substate".
294
- * @example (ng2)
295
- * ```
296
294
*
297
- * transitionService.onBefore({ to: 'home' }, function(trans: Transition, injector: Injector) {
298
- * return injector.get('$state').target("home.dashboard");
299
- * });
295
+ * @example
296
+ * ```js
297
+ * // ng2
298
+ * transitionService.onBefore({ to: 'home' }, (trans: Transition) =>
299
+ * trans.router.stateService.target("home.dashboard"));
300
300
* ```
301
301
*
302
302
* #### Data Driven Default Substate
@@ -305,9 +305,9 @@ export interface IHookRegistry {
305
305
* which has `defaultSubstate: "some.sub.state"` defined. See: [[Transition.to]] which returns the "to state"
306
306
* definition.
307
307
*
308
- * @example (ng1)
309
- * ```
310
- *
308
+ * @example
309
+ * ```js
310
+ * // ng1
311
311
* // state declaration
312
312
* {
313
313
* name: 'home',
@@ -320,25 +320,26 @@ export interface IHookRegistry {
320
320
* return state.defaultSubstate != null;
321
321
* }
322
322
* }
323
- * $transitions.onBefore(criteria, function(trans: Transition, $injector) {
324
- * return $injector.get("$state").target(trans.to().defaultSubstate);
323
+ *
324
+ * $transitions.onBefore(criteria, function(trans: Transition) {
325
+ * var substate = trans.to().defaultSubstate;
326
+ * return trans.router.stateService.target(substate);
325
327
* });
326
328
* ```
327
329
*
328
330
*
329
331
* #### Require authentication
330
332
*
331
- * This example cancels a transition to a state which requires authentication, if the user is
332
- * not currently authenticated.
333
+ * This example cancels a transition to a state which requires authentication, if the user is not currently authenticated.
333
334
*
334
- * This example assumes a state tree where all states which require authentication are children of
335
- * a parent `'requireauth'` state. This example assumes `MyAuthService` synchronously returns a boolean from
336
- * `isAuthenticated()`.
337
- * @example (ng1)
338
- * ```
335
+ * This example assumes a state tree where all states which require authentication are children of a parent `'requireauth'` state.
336
+ * This example assumes `MyAuthService` synchronously returns a boolean from `isAuthenticated()`.
339
337
*
340
- * $transitions.onBefore( { to: 'requireauth.*', from: '*' }, function(trans, $inj) {
341
- * var myAuthService = $inj.get('MyAuthService');
338
+ * @example
339
+ * ```js
340
+ * // ng1
341
+ * $transitions.onBefore( { to: 'requireauth.**' }, function(trans) {
342
+ * var myAuthService = trans.injector().get('MyAuthService');
342
343
* // If isAuthenticated returns false, the transition is cancelled.
343
344
* return myAuthService.isAuthenticated();
344
345
* });
@@ -389,12 +390,12 @@ export interface IHookRegistry {
389
390
* - `MyAuthService.authenticate()` presents a login dialog, and returns a promise which is resolved
390
391
* or rejected, whether or not the login attempt was successful.
391
392
*
392
- * @example (ng1)
393
- * ```
394
- *
395
- * $transitions.onStart( { to: 'auth.*' }, function(trans, $injector ) {
396
- * var $state = $injector.get('$state') ;
397
- * var MyAuthService = $ injector.get('MyAuthService');
393
+ * @example
394
+ * ```js
395
+ * // ng1
396
+ * $transitions.onStart( { to: 'auth.*' }, function(trans) {
397
+ * var $state = trans.router.stateService ;
398
+ * var MyAuthService = trans. injector() .get('MyAuthService');
398
399
*
399
400
* // If the user is not authenticated
400
401
* if (!MyAuthService.isAuthenticated()) {
@@ -464,8 +465,8 @@ export interface IHookRegistry {
464
465
* @example
465
466
* ```
466
467
*
467
- * $transitions.onEnter({ entering: 'admin' }, function(transition, injector, state) {
468
- * var AuditService = injector.get('AuditService');
468
+ * $transitions.onEnter({ entering: 'admin' }, function(transition, state) {
469
+ * var AuditService = trans. injector() .get('AuditService');
469
470
* AuditService.log("Entered " + state.name + " module while transitioning to " + transition.to().name);
470
471
* }
471
472
* ```
@@ -476,14 +477,16 @@ export interface IHookRegistry {
476
477
* ```
477
478
* {
478
479
* name: 'admin',
479
- * template : '<div ui-view/> ',
480
- * onEnter: function(transition, injector, state) {
481
- * var AuditService = injector.get('AuditService');
480
+ * component : 'admin ',
481
+ * onEnter: function($ transition$, $ state$ ) {
482
+ * var AuditService = $transition$. injector() .get('AuditService');
482
483
* AuditService.log("Entered " + state.name + " module while transitioning to " + transition.to().name);
483
484
* }
484
485
* }
485
486
* ```
486
487
*
488
+ * Note: A state declaration's `onEnter` function is injected for Angular 1 only.
489
+ *
487
490
* @param matchCriteria defines which Transitions the Hook should be invoked for.
488
491
* @param callback the hook function which will be injected and invoked.
489
492
* @returns a function which deregisters the hook.
@@ -520,6 +523,7 @@ export interface IHookRegistry {
520
523
* Instead of registering `onRetain` hooks using the [[TransitionService]], you may define an `onRetain` hook
521
524
* directly on a state declaration (see: [[StateDeclaration.onRetain]]).
522
525
*
526
+ * Note: A state declaration's `onRetain` function is injected for Angular 1 only.
523
527
*
524
528
* @param matchCriteria defines which Transitions the Hook should be invoked for.
525
529
* @param callback the hook function which will be injected and invoked.
@@ -558,6 +562,8 @@ export interface IHookRegistry {
558
562
* Instead of registering `onExit` hooks using the [[TransitionService]], you may define an `onExit` hook
559
563
* directly on a state declaration (see: [[StateDeclaration.onExit]]).
560
564
*
565
+ * Note: A state declaration's `onExit` function is injected for Angular 1 only.
566
+ *
561
567
* @param matchCriteria defines which Transitions the Hook should be invoked for.
562
568
* @param callback the hook function which will be injected and invoked.
563
569
* @returns a function which deregisters the hook.
@@ -576,11 +582,9 @@ export interface IHookRegistry {
576
582
*
577
583
* ### Lifecycle
578
584
*
579
- * `onFinish` hooks are invoked asynchronously, in priority order, just before the Transition completes, after
580
- * all states are entered and exited.
581
585
* `onFinish` hooks are invoked after the `onEnter` phase is complete.
582
586
* These hooks are invoked just before the transition is "committed".
583
- * The registered `onFinish` hooks are invoked in priority order.
587
+ * Each hook is invoked in priority order.
584
588
*
585
589
* ### Return value
586
590
*
0 commit comments