Skip to content

Commit 639e056

Browse files
committed
feat($state): .reload() returns state transition promise
You could want to perform an action after a state is reloaded Since .reload() is a shortcut for .transitionTo(), it makes sense to pass on the promise
1 parent eb1712b commit 639e056

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/state.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,12 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
644644
* reload: true, inherit: false, notify: false
645645
* });
646646
* </pre>
647+
*
648+
* @returns {promise} A promise representing the state of the new transition. See
649+
* {@link ui.router.state.$state#methods_go $state.go}.
647650
*/
648651
$state.reload = function reload() {
649-
$state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: false });
652+
return $state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: false });
650653
};
651654

652655
/**

test/stateSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,16 @@ describe('state', function () {
487487
});
488488

489489
describe('.reload()', function () {
490+
it('returns a promise for the state transition', inject(function ($state, $q) {
491+
var trans = $state.transitionTo(A, {});
492+
$q.flush();
493+
expect(resolvedValue(trans)).toBe(A);
494+
495+
trans = $state.reload();
496+
$q.flush();
497+
expect(resolvedValue(trans)).toBe(A);
498+
}));
499+
490500
it('should reload the current state with the current parameters', inject(function ($state, $q, $timeout) {
491501
$state.transitionTo('resolveTimeout', { foo: "bar" });
492502
$q.flush();

0 commit comments

Comments
 (0)