Skip to content

Commit

Permalink
fix(ng1.uiSrefActive): update sref-active after existing transition-i…
Browse files Browse the repository at this point in the history
…n-progress completes

Closes #2908
  • Loading branch information
christopherthielen committed Sep 1, 2016
1 parent f674151 commit 0994c71
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ng1/directives/stateDirectives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import IScope = angular.IScope;
import IInterpolateService = angular.IInterpolateService;
import {TransitionService} from "../../transition/transitionService";
import {State} from "../../state/stateObject";
import {UIRouter} from "../../router";

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

function updateAfterTransition(trans) { trans.promise.then(update); }
$scope.$on('$stateChangeSuccess', update);
$scope.$on('$destroy', <any> $transitions.onStart({}, (trans) => trans.promise.then(update) && null));
$scope.$on('$destroy', <any> $transitions.onStart({}, updateAfterTransition));
if ($uiRouter.globals.transition) {
updateAfterTransition($uiRouter.globals.transition);
}

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

0 comments on commit 0994c71

Please sign in to comment.