@@ -137,6 +137,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
137137
138138 if ( path ) {
139139 if ( ! base ) throw new Error ( "No reference point given for path '" + name + "'" ) ;
140+ base = findState ( base ) ;
141+
140142 var rel = name . split ( "." ) , i = 0 , pathLength = rel . length , current = base ;
141143
142144 for ( ; i < pathLength ; i ++ ) {
@@ -973,8 +975,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
973975 *
974976 * @description
975977 * Similar to {@link ui.router.state.$state#methods_includes $state.includes},
976- * but only checks for the full state name. If params is supplied then it will be
977- * tested for strict equality against the current active params object, so all params
978+ * but only checks for the full state name. If params is supplied then it will be
979+ * tested for strict equality against the current active params object, so all params
978980 * must match with none missing and no extras.
979981 *
980982 * @example
@@ -990,13 +992,19 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
990992 * <div ng-class="{highlighted: $state.is('.item')}">Item</div>
991993 * </pre>
992994 *
993- * @param {string|object } stateName The state name (absolute or relative) or state object you'd like to check.
994- * @param {object= } params A param object, e.g. `{sectionId: section.id}`, that you'd like
995+ * @param {string|object } stateOrName The state name (absolute or relative) or state object you'd like to check.
996+ * @param {object= } params A param object, e.g. `{sectionId: section.id}`, that you'd like
995997 * to test against the current active state.
998+ * @param {object= } options An options object. The options are:
999+ *
1000+ * - **`relative`** - {string|object} - If `stateOrName` is a relative state name and `options.relative` is set, .is will
1001+ * test relative to `options.relative` state (or name).
1002+ *
9961003 * @returns {boolean } Returns true if it is the state.
9971004 */
998- $state . is = function is ( stateOrName , params ) {
999- var state = findState ( stateOrName ) ;
1005+ $state . is = function is ( stateOrName , params , options ) {
1006+ options = extend ( { relative : $state . $current } , options || { } ) ;
1007+ var state = findState ( stateOrName , options . relative ) ;
10001008
10011009 if ( ! isDefined ( state ) ) {
10021010 return undefined ;
@@ -1051,19 +1059,25 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
10511059 *
10521060 * @param {string } stateOrName A partial name, relative name, or glob pattern
10531061 * to be searched for within the current state name.
1054- * @param {object } params A param object, e.g. `{sectionId: section.id}`,
1062+ * @param {object= } params A param object, e.g. `{sectionId: section.id}`,
10551063 * that you'd like to test against the current active state.
1064+ * @param {object= } options An options object. The options are:
1065+ *
1066+ * - **`relative`** - {string|object=} - If `stateOrName` is a relative state reference and `options.relative` is set,
1067+ * .includes will test relative to `options.relative` state (or name).
1068+ *
10561069 * @returns {boolean } Returns true if it does include the state
10571070 */
1058- $state . includes = function includes ( stateOrName , params ) {
1071+ $state . includes = function includes ( stateOrName , params , options ) {
1072+ options = extend ( { relative : $state . $current } , options || { } ) ;
10591073 if ( isString ( stateOrName ) && isGlob ( stateOrName ) ) {
10601074 if ( ! doesStateMatchGlob ( stateOrName ) ) {
10611075 return false ;
10621076 }
10631077 stateOrName = $state . $current . name ;
10641078 }
1065- var state = findState ( stateOrName ) ;
10661079
1080+ var state = findState ( stateOrName , options . relative ) ;
10671081 if ( ! isDefined ( state ) ) {
10681082 return undefined ;
10691083 }
@@ -1132,13 +1146,14 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
11321146 * @description
11331147 * Returns the state configuration object for any specific state or all states.
11341148 *
1135- * @param {string|Sbject = } stateOrName (absolute or relative) If provided, will only get the config for
1149+ * @param {string|object = } stateOrName (absolute or relative) If provided, will only get the config for
11361150 * the requested state. If not provided, returns an array of ALL state configs.
1151+ * @param {string|object= } context When stateOrName is a relative state reference, the state will be retrieved relative to context.
11371152 * @returns {Object|Array } State configuration object or array of all objects.
11381153 */
11391154 $state . get = function ( stateOrName , context ) {
11401155 if ( arguments . length === 0 ) return objectKeys ( states ) . map ( function ( name ) { return states [ name ] . self ; } ) ;
1141- var state = findState ( stateOrName , context ) ;
1156+ var state = findState ( stateOrName , context || $state . $current ) ;
11421157 return ( state && state . self ) ? state . self : null ;
11431158 } ;
11441159
0 commit comments