Skip to content

Commit

Permalink
fix($state): reload() now reinvokes controllers
Browse files Browse the repository at this point in the history
- change reload() to use notify: true

fixes #582
  • Loading branch information
christopherthielen committed Nov 8, 2014
1 parent fdd2f2c commit 7344342
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,15 +632,15 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
* `reload()` is just an alias for:
* <pre>
* $state.transitionTo($state.current, $stateParams, {
* reload: true, inherit: false, notify: false
* reload: true, inherit: false, notify: true
* });
* </pre>
*
* @returns {promise} A promise representing the state of the new transition. See
* {@link ui.router.state.$state#methods_go $state.go}.
*/
$state.reload = function reload() {
return $state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: false });
return $state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: true });
};

/**
Expand Down
18 changes: 16 additions & 2 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('state', function () {
};
}

var A = { data: {} },
var A = { data: {}, controller: function() { log += "controller;"; } },
B = {},
C = {},
D = { params: { x: null, y: null } },
Expand Down Expand Up @@ -95,7 +95,8 @@ describe('state', function () {
value: function ($timeout) {
return $timeout(function() { log += "Success!"; }, 1);
}
}
},
controller: function() { log += "controller;"}
})
.state('badParam', {
url: "/bad/{param:int}"
Expand Down Expand Up @@ -515,6 +516,19 @@ describe('state', function () {
$timeout.flush();
expect(log).toBe('Success!Success!');
}));

it('should invoke the controller', inject(function ($state, $q, $timeout, $rootScope, $compile) {
$compile('<div ui-view/>')($rootScope);
$state.transitionTo('resolveTimeout', { foo: "bar" });
$timeout.flush();
$q.flush();
expect(log).toBe('Success!controller;');

$state.reload();
$timeout.flush();
$q.flush();
expect(log).toBe('Success!controller;Success!controller;');
}));
});

describe('.is()', function () {
Expand Down

0 comments on commit 7344342

Please sign in to comment.