@@ -137,6 +137,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
137
137
138
138
if ( path ) {
139
139
if ( ! base ) throw new Error ( "No reference point given for path '" + name + "'" ) ;
140
+ base = findState ( base ) ;
141
+
140
142
var rel = name . split ( "." ) , i = 0 , pathLength = rel . length , current = base ;
141
143
142
144
for ( ; i < pathLength ; i ++ ) {
@@ -973,8 +975,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
973
975
*
974
976
* @description
975
977
* 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
978
980
* must match with none missing and no extras.
979
981
*
980
982
* @example
@@ -990,13 +992,19 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
990
992
* <div ng-class="{highlighted: $state.is('.item')}">Item</div>
991
993
* </pre>
992
994
*
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
995
997
* 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
+ *
996
1003
* @returns {boolean } Returns true if it is the state.
997
1004
*/
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 ) ;
1000
1008
1001
1009
if ( ! isDefined ( state ) ) {
1002
1010
return undefined ;
@@ -1051,19 +1059,25 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1051
1059
*
1052
1060
* @param {string } stateOrName A partial name, relative name, or glob pattern
1053
1061
* 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}`,
1055
1063
* 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
+ *
1056
1069
* @returns {boolean } Returns true if it does include the state
1057
1070
*/
1058
- $state . includes = function includes ( stateOrName , params ) {
1071
+ $state . includes = function includes ( stateOrName , params , options ) {
1072
+ options = extend ( { relative : $state . $current } , options || { } ) ;
1059
1073
if ( isString ( stateOrName ) && isGlob ( stateOrName ) ) {
1060
1074
if ( ! doesStateMatchGlob ( stateOrName ) ) {
1061
1075
return false ;
1062
1076
}
1063
1077
stateOrName = $state . $current . name ;
1064
1078
}
1065
- var state = findState ( stateOrName ) ;
1066
1079
1080
+ var state = findState ( stateOrName , options . relative ) ;
1067
1081
if ( ! isDefined ( state ) ) {
1068
1082
return undefined ;
1069
1083
}
@@ -1132,13 +1146,14 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1132
1146
* @description
1133
1147
* Returns the state configuration object for any specific state or all states.
1134
1148
*
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
1136
1150
* 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.
1137
1152
* @returns {Object|Array } State configuration object or array of all objects.
1138
1153
*/
1139
1154
$state . get = function ( stateOrName , context ) {
1140
1155
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 ) ;
1142
1157
return ( state && state . self ) ? state . self : null ;
1143
1158
} ;
1144
1159
0 commit comments