@@ -820,11 +820,33 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
820820 * });
821821 * </pre>
822822 *
823+ * @param {string=|object= } state - A state name or a state object, which is the root of the resolves to be re-resolved.
824+ * @example
825+ * <pre>
826+ * //assuming app application consists of 3 states: 'contacts', 'contacts.detail', 'contacts.detail.item'
827+ * //and current state is 'contacts.detail.item'
828+ * var app angular.module('app', ['ui.router']);
829+ *
830+ * app.controller('ctrl', function ($scope, $state) {
831+ * $scope.reload = function(){
832+ * //will reload 'contact.detail' and 'contact.detail.item' states
833+ * $state.reload('contact.detail');
834+ * }
835+ * });
836+ * </pre>
837+ *
838+ * `reload()` is just an alias for:
839+ * <pre>
840+ * $state.transitionTo($state.current, $stateParams, {
841+ * reload: true, inherit: false, notify: true
842+ * });
843+ * </pre>
844+
823845 * @returns {promise } A promise representing the state of the new transition. See
824846 * {@link ui.router.state.$state#methods_go $state.go}.
825847 */
826- $state . reload = function reload ( ) {
827- return $state . transitionTo ( $state . current , $stateParams , { reload : true , inherit : false , notify : true } ) ;
848+ $state . reload = function reload ( state ) {
849+ return $state . transitionTo ( $state . current , $stateParams , { reload : state || true , inherit : false , notify : true } ) ;
828850 } ;
829851
830852 /**
@@ -928,9 +950,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
928950 * - **`relative`** - {object=}, When transitioning with relative path (e.g '^'),
929951 * defines which state to be relative from.
930952 * - **`notify`** - {boolean=true}, If `true` will broadcast $stateChangeStart and $stateChangeSuccess events.
931- * - **`reload`** (v0.2.5) - {boolean=false}, If `true` will force transition even if the state or params
953+ * - **`reload`** (v0.2.5) - {boolean=false|string=|object= }, If `true` will force transition even if the state or params
932954 * have not changed, aka a reload of the same state. It differs from reloadOnSearch because you'd
933955 * use this when you want to force a reload when *everything* is the same, including search params.
956+ * if String, then will reload the state with the name given in reload, and any children.
957+ * if Object, then a stateObj is expected, will reload the state found in stateObj, and any chhildren.
934958 *
935959 * @returns {promise } A promise representing the state of the new transition. See
936960 * {@link ui.router.state.$state#methods_go $state.go}.
@@ -975,21 +999,39 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
975999
9761000 // Starting from the root of the path, keep all levels that haven't changed
9771001 var keep = 0 , state = toPath [ keep ] , locals = root . locals , toLocals = [ ] ;
1002+ var skipTriggerReloadCheck = false ;
9781003
9791004 if ( ! options . reload ) {
9801005 while ( state && state === fromPath [ keep ] && state . ownParams . $$equals ( toParams , fromParams ) ) {
9811006 locals = toLocals [ keep ] = state . locals ;
9821007 keep ++ ;
9831008 state = toPath [ keep ] ;
9841009 }
1010+ } else if ( isString ( options . reload ) || isObject ( options . reload ) ) {
1011+ if ( isObject ( options . reload ) && ! options . reload . name ) {
1012+ throw new Error ( 'Invalid reload state object' ) ;
1013+ }
1014+
1015+ var reloadState = options . reload === true ? fromPath [ 0 ] : findState ( options . reload ) ;
1016+ if ( options . reload && ! reloadState ) {
1017+ throw new Error ( "No such reload state '" + ( isString ( options . reload ) ? options . reload : options . reload . name ) + "'" ) ;
1018+ }
1019+
1020+ skipTriggerReloadCheck = true ;
1021+
1022+ while ( state && state === fromPath [ keep ] && state !== reloadState ) {
1023+ locals = toLocals [ keep ] = state . locals ;
1024+ keep ++ ;
1025+ state = toPath [ keep ] ;
1026+ }
9851027 }
9861028
9871029 // If we're going to the same state and all locals are kept, we've got nothing to do.
9881030 // But clear 'transition', as we still want to cancel any other pending transitions.
9891031 // TODO: We may not want to bump 'transition' if we're called from a location change
9901032 // that we've initiated ourselves, because we might accidentally abort a legitimate
9911033 // transition initiated from code?
992- if ( shouldTriggerReload ( to , from , locals , options ) ) {
1034+ if ( ! skipTriggerReloadCheck && shouldTriggerReload ( to , from , locals , options ) ) {
9931035 if ( to . self . reloadOnSearch !== false ) $urlRouter . update ( ) ;
9941036 $state . transition = null ;
9951037 return $q . when ( $state . current ) ;
0 commit comments