Skip to content

Commit 0994c71

Browse files
fix(ng1.uiSrefActive): update sref-active after existing transition-in-progress completes
Closes #2908
1 parent f674151 commit 0994c71

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ng1/directives/stateDirectives.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import IScope = angular.IScope;
1818
import IInterpolateService = angular.IInterpolateService;
1919
import {TransitionService} from "../../transition/transitionService";
2020
import {State} from "../../state/stateObject";
21+
import {UIRouter} from "../../router";
2122

2223
/** @hidden */
2324
function parseStateRef(ref: string, current: string) {
@@ -321,8 +322,8 @@ function $StateRefDynamicDirective($state: StateService, $timeout: ITimeoutServi
321322
* to both the <div> and <a> elements. It is important to note that the state
322323
* names/globs passed to ui-sref-active shadow the state provided by ui-sref.
323324
*/
324-
let uiSrefActive = ['$state', '$stateParams', '$interpolate', '$transitions',
325-
function $StateRefActiveDirective($state: StateService, $stateParams: Obj, $interpolate: IInterpolateService, $transitions: TransitionService) {
325+
let uiSrefActive = ['$state', '$stateParams', '$interpolate', '$transitions', '$uiRouter',
326+
function $StateRefActiveDirective($state: StateService, $stateParams: Obj, $interpolate: IInterpolateService, $transitions: TransitionService, $uiRouter: UIRouter) {
326327
return {
327328
restrict: "A",
328329
controller: ['$scope', '$element', '$attrs', '$timeout',
@@ -362,8 +363,12 @@ function $StateRefActiveDirective($state: StateService, $stateParams: Obj, $inte
362363
return deregister;
363364
};
364365

366+
function updateAfterTransition(trans) { trans.promise.then(update); }
365367
$scope.$on('$stateChangeSuccess', update);
366-
$scope.$on('$destroy', <any> $transitions.onStart({}, (trans) => trans.promise.then(update) && null));
368+
$scope.$on('$destroy', <any> $transitions.onStart({}, updateAfterTransition));
369+
if ($uiRouter.globals.transition) {
370+
updateAfterTransition($uiRouter.globals.transition);
371+
}
367372

368373
function addState(stateName: string, stateParams: Obj, activeClass: string) {
369374
var state = $state.get(stateName, stateContext($element));

0 commit comments

Comments
 (0)