Skip to content

Commit a1f0755

Browse files
committed
feat($stateChangeStart): Add options to event
- Add options as a 5th parameter to the $stateChangeStart event - As per #1620
1 parent f92d3dd commit a1f0755

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/state.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
10771077
* })
10781078
* </pre>
10791079
*/
1080-
if ($rootScope.$broadcast('$stateChangeStart', to.self, toParams, from.self, fromParams).defaultPrevented) {
1080+
if ($rootScope.$broadcast('$stateChangeStart', to.self, toParams, from.self, fromParams, options).defaultPrevented) {
10811081
$rootScope.$broadcast('$stateChangeCancel', to.self, toParams, from.self, fromParams);
10821082
$urlRouter.update();
10831083
return TransitionPrevented;

test/stateSpec.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ describe('state', function () {
176176
return jasmine.getEnv().currentSpec.$injector.get(what);
177177
}
178178

179-
function initStateTo(state, optionalParams) {
179+
function initStateTo(state, optionalParams, optionalOptions) {
180180
var $state = $get('$state'), $q = $get('$q');
181-
$state.transitionTo(state, optionalParams || {});
181+
$state.transitionTo(state, optionalParams || {}, optionalOptions || {});
182182
$q.flush();
183183
expect($state.current).toBe(state);
184184
}
@@ -211,7 +211,7 @@ describe('state', function () {
211211
initStateTo(RS);
212212
$location.search({term: 'hello'});
213213
var called;
214-
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams) {
214+
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams, options) {
215215
called = true
216216
});
217217
$q.flush();
@@ -223,7 +223,7 @@ describe('state', function () {
223223
initStateTo(RS);
224224
$location.search({term: 'hello'});
225225
var called;
226-
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams) {
226+
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams, options) {
227227
called = true
228228
});
229229
$q.flush();
@@ -235,7 +235,7 @@ describe('state', function () {
235235
initStateTo(RS);
236236
var called;
237237
$state.go(".", { term: 'goodbye' });
238-
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams) {
238+
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams, options) {
239239
called = true
240240
});
241241
$q.flush();
@@ -248,7 +248,7 @@ describe('state', function () {
248248
initStateTo(RSP, { doReload: 'foo' });
249249
expect($state.params.doReload).toEqual('foo');
250250
var called;
251-
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams) {
251+
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams, options) {
252252
called = true
253253
});
254254
$state.transitionTo(RSP, { doReload: 'bar' });
@@ -264,19 +264,20 @@ describe('state', function () {
264264
}));
265265

266266
it('triggers $stateChangeStart', inject(function ($state, $q, $rootScope) {
267-
initStateTo(E, { i: 'iii' });
267+
initStateTo(E, { i: 'iii' }, { anOption: true });
268268
var called;
269-
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams) {
269+
$rootScope.$on('$stateChangeStart', function (ev, to, toParams, from, fromParams, options) {
270270
expect(from).toBe(E);
271271
expect(fromParams).toEqual({ i: 'iii' });
272272
expect(to).toBe(D);
273273
expect(toParams).toEqual({ x: '1', y: '2' });
274+
expect(options.anOption).toBe(false);
274275

275276
expect($state.current).toBe(from); // $state not updated yet
276277
expect($state.params).toEqual(fromParams);
277278
called = true;
278279
});
279-
$state.transitionTo(D, { x: '1', y: '2' });
280+
$state.transitionTo(D, { x: '1', y: '2' }, { anOption: false });
280281
$q.flush();
281282
expect(called).toBeTruthy();
282283
expect($state.current).toBe(D);

0 commit comments

Comments
 (0)