Skip to content

Commit 5a38ac3

Browse files
scooper91christopherthielen
authored andcommitted
cherry-pick a1f0755 from 0.2.17
1 parent 120d7ad commit 5a38ac3

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/ng1/stateEvents.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ import {Transition} from "../transition/transition";
6464
let fromParams = $transition$.params("from");
6565

6666
if (enabledEvents.$stateChangeSuccess) {
67-
let startEvent = $rootScope.$broadcast('$stateChangeStart', $transition$.to(), toParams, $transition$.from(), fromParams, $transition$);
67+
let startEvent = $rootScope.$broadcast('$stateChangeStart', $transition$.to(), toParams, $transition$.from(), fromParams, $transition$.options(), $transition$);
6868

6969
if (startEvent.defaultPrevented) {
7070
if (enabledEvents.$stateChangeCancel) {
71-
$rootScope.$broadcast('$stateChangeCancel', $transition$.to(), toParams, $transition$.from(), fromParams, $transition$);
71+
$rootScope.$broadcast('$stateChangeCancel', $transition$.to(), toParams, $transition$.from(), fromParams, $transition$.options(), $transition$);
7272
}
7373
//Don't update and resync url if there's been a new transition started. see issue #2238, #600
7474
if ($state.transition == null) $urlRouter.update();
@@ -90,7 +90,7 @@ import {Transition} from "../transition/transition";
9090
* @param from
9191
* @param fromParams
9292
*/
93-
$rootScope.$broadcast('$stateChangeSuccess', $transition$.to(), toParams, $transition$.from(), fromParams);
93+
$rootScope.$broadcast('$stateChangeSuccess', $transition$.to(), toParams, $transition$.from(), fromParams, $transition$.options(), $transition$);
9494
});
9595
}
9696

@@ -117,7 +117,7 @@ import {Transition} from "../transition/transition";
117117
* @param {Object} fromParams The params supplied to the `fromState`.
118118
* @param {Error} error The resolve error object.
119119
*/
120-
let evt = $rootScope.$broadcast('$stateChangeError', $transition$.to(), toParams, $transition$.from(), fromParams, error);
120+
let evt = $rootScope.$broadcast('$stateChangeError', $transition$.to(), toParams, $transition$.from(), fromParams, error, $transition$.options(), $transition$);
121121

122122
if (!evt.defaultPrevented) {
123123
$urlRouter.update();

test/stateEventsSpec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ describe('UI-Router v0.2.x $state events', function () {
6262
return $injector.get(what);
6363
}
6464

65-
function initStateTo(state, params) {
65+
function initStateTo(state, optionalParams, optionalOptions) {
6666
var $state = $get('$state'), $q = $get('$q');
67-
$state.transitionTo(state, params || {});
67+
$state.transitionTo(state, optionalParams || {}, optionalOptions || {});
6868
$q.flush();
6969
expect($state.current).toBe(state);
7070
}
7171

7272
describe('.transitionTo()', function () {
7373
it('triggers $stateChangeStart', inject(function ($state, $q, $rootScope) {
74-
initStateTo(E, {i: 'iii'});
74+
initStateTo(E, {i: 'iii'}, { anOption: true });
7575
var called;
76-
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams) {
76+
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams, options) {
7777
expect(from).toBe(E);
7878

7979
expect(obj(fromParams)).toEqual({i: 'iii'});
@@ -82,11 +82,13 @@ describe('UI-Router v0.2.x $state events', function () {
8282

8383
expect(obj(toParams)).toEqual({x: '1', y: '2'});
8484

85+
expect(options.custom.anOption).toBe(false);
86+
8587
expect($state.current).toBe(from); // $state not updated yet
8688
expect(obj($state.params)).toEqual(obj(fromParams));
8789
called = true;
8890
});
89-
$state.transitionTo(D, {x: '1', y: '2'});
91+
$state.transitionTo(D, {x: '1', y: '2'}, { custom: { anOption: false } });
9092
$q.flush();
9193
expect(called).toBeTruthy();
9294
expect($state.current).toBe(D);

0 commit comments

Comments
 (0)