@@ -924,9 +924,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
924
924
$stateParams . $off ( ) ;
925
925
926
926
if ( options . location && to . navigable ) {
927
- $urlRouter . push ( to . navigable . url , to . navigable . locals . globals . $stateParams , {
928
- replace : options . location === 'replace'
929
- } ) ;
927
+ $urlRouter . push ( to . navigable . url , $stateParams , { replace : options . location === 'replace' } ) ;
930
928
}
931
929
932
930
if ( options . notify ) {
@@ -1159,29 +1157,30 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1159
1157
return ( state && state . self ) ? state . self : null ;
1160
1158
} ;
1161
1159
1162
- function resolveState ( state , params , paramsAreFiltered , inherited , dst ) {
1160
+ function resolveState ( state , params , filtered , inherited , dst ) {
1163
1161
// Make a restricted $stateParams with only the parameters that apply to this state if
1164
1162
// necessary. In addition to being available to the controller and onEnter/onExit callbacks,
1165
1163
// we also need $stateParams to be available for any $injector calls we make during the
1166
1164
// dependency resolution process.
1167
- var $stateParams = ( paramsAreFiltered ) ? params : filterByKeys ( objectKeys ( state . params ) , params ) ;
1168
- var locals = { $stateParams : $stateParams } ;
1165
+ var locals = { $stateParams : ( filtered ) ? params : $stateParams . $localize ( state , params ) } ;
1169
1166
1170
1167
// Resolve 'global' dependencies for the state, i.e. those not specific to a view.
1171
1168
// We're also including $stateParams in this; that way the parameters are restricted
1172
1169
// to the set that should be visible to the state, and are independent of when we update
1173
1170
// the global $state and $stateParams values.
1174
1171
dst . resolve = $resolve . resolve ( state . resolve , locals , dst . resolve , state ) ;
1172
+
1175
1173
var promises = [ dst . resolve . then ( function ( globals ) {
1176
1174
dst . globals = globals ;
1177
1175
} ) ] ;
1176
+
1178
1177
if ( inherited ) promises . push ( inherited ) ;
1179
1178
1180
1179
// Resolve template and dependencies for all views.
1181
1180
forEach ( state . views , function ( view , name ) {
1182
1181
var injectables = ( view . resolve && view . resolve !== state . resolve ? view . resolve : { } ) ;
1183
1182
injectables . $template = [ function ( ) {
1184
- return $view . load ( name , { view : view , locals : locals , params : $stateParams } ) || '' ;
1183
+ return $view . load ( name , { view : view , locals : locals , params : locals . $stateParams } ) || '' ;
1185
1184
} ] ;
1186
1185
1187
1186
promises . push ( $resolve . resolve ( injectables , locals , dst . resolve , state ) . then ( function ( result ) {
@@ -1212,73 +1211,78 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1212
1211
$StateParamsProvider . $inject = [ ] ;
1213
1212
function $StateParamsProvider ( ) {
1214
1213
1215
- var observers = { } , current = { } ;
1214
+ function stateParamsFactory ( ) {
1215
+ var observers = { } , current = { } ;
1216
1216
1217
- function unhook ( key , func ) {
1218
- return function ( ) {
1219
- forEach ( key . split ( " " ) , function ( k ) {
1220
- observers [ k ] . splice ( observers [ k ] . indexOf ( func ) , 1 ) ;
1217
+ function unhook ( key , func ) {
1218
+ return function ( ) {
1219
+ forEach ( key . split ( " " ) , function ( k ) {
1220
+ observers [ k ] . splice ( observers [ k ] . indexOf ( func ) , 1 ) ;
1221
+ } ) ;
1222
+ } ;
1223
+ }
1224
+
1225
+ function observeChange ( key , val ) {
1226
+ if ( ! observers [ key ] || ! observers [ key ] . length ) return ;
1227
+
1228
+ forEach ( observers [ key ] , function ( func ) {
1229
+ func ( val ) ;
1221
1230
} ) ;
1222
- } ;
1223
- }
1231
+ }
1224
1232
1225
- function observeChange ( key , val ) {
1226
- if ( ! observers [ key ] || ! observers [ key ] . length ) return ;
1233
+ function StateParams ( ) {
1234
+ }
1227
1235
1228
- forEach ( observers [ key ] , function ( func ) {
1229
- func ( ) ;
1230
- } ) ;
1231
- }
1236
+ StateParams . prototype . $digest = function ( ) {
1237
+ forEach ( this , function ( val , key ) {
1238
+ if ( val == current [ key ] || ! this . hasOwnProperty ( key ) ) return ;
1239
+ current [ key ] = val ;
1240
+ observeChange ( key , val ) ;
1241
+ } , this ) ;
1242
+ } ;
1232
1243
1233
- function StateParams ( ) {
1234
- }
1244
+ StateParams . prototype . $set = function ( params ) {
1245
+ forEach ( params , function ( val , key ) {
1246
+ this [ key ] = val ;
1247
+ observeChange ( key ) ;
1248
+ } , this ) ;
1249
+ this . $sync ( ) ;
1250
+ } ;
1235
1251
1236
- StateParams . prototype . $digest = function ( ) {
1237
- forEach ( this , function ( val , key ) {
1238
- if ( val == current [ key ] || ! this . hasOwnProperty ( key ) ) return ;
1239
- current [ key ] = val ;
1240
- observeChange ( key , val ) ;
1241
- } , this ) ;
1242
- } ;
1252
+ StateParams . prototype . $sync = function ( ) {
1253
+ copy ( this , current ) ;
1254
+ } ;
1243
1255
1244
- StateParams . prototype . $set = function ( params ) {
1245
- forEach ( params , function ( val , key ) {
1246
- this [ key ] = val ;
1247
- observeChange ( key ) ;
1248
- } , this ) ;
1249
- this . $sync ( ) ;
1250
- } ;
1256
+ StateParams . prototype . $off = function ( ) {
1257
+ observers = { } ;
1258
+ } ;
1251
1259
1252
- StateParams . prototype . $sync = function ( ) {
1253
- copy ( this , current ) ;
1254
- } ;
1260
+ StateParams . prototype . $localize = function ( state , params ) {
1261
+ var localized = new StateParams ( ) ;
1262
+ params = params || this ;
1255
1263
1256
- StateParams . prototype . $off = function ( ) {
1257
- observers = { } ;
1258
- } ;
1264
+ forEach ( state . params , function ( val , key ) {
1265
+ localized [ key ] = params [ key ] ;
1266
+ } ) ;
1267
+ return localized ;
1268
+ } ;
1259
1269
1260
- StateParams . prototype . $localize = function ( state ) {
1261
- var localized = new StateParams ( ) ;
1270
+ StateParams . prototype . $observe = function ( key , func ) {
1271
+ forEach ( key . split ( " " ) , function ( k ) {
1272
+ ( observers [ k ] || ( observers [ k ] = [ ] ) ) . push ( func ) ;
1273
+ } ) ;
1274
+ return unhook ( key , func ) ;
1275
+ } ;
1262
1276
1263
- forEach ( state . params , function ( val , key ) {
1264
- localized [ key ] = this [ key ] ;
1265
- } , this ) ;
1266
- return localized ;
1267
- } ;
1277
+ return new StateParams ( ) ;
1278
+ }
1268
1279
1269
- StateParams . prototype . $observe = function ( key , func ) {
1270
- forEach ( key . split ( " " ) , function ( k ) {
1271
- ( observers [ k ] || ( observers [ k ] = [ ] ) ) . push ( func ) ;
1272
- } ) ;
1273
- return unhook ( key , func ) ;
1274
- } ;
1280
+ var global = stateParamsFactory ( ) ;
1275
1281
1276
1282
this . $get = $get ;
1277
1283
$get . $inject = [ '$rootScope' ] ;
1278
1284
function $get ( $rootScope ) {
1279
1285
1280
- var global = new StateParams ( ) ;
1281
-
1282
1286
$rootScope . $watch ( function ( ) {
1283
1287
global . $digest ( ) ;
1284
1288
} ) ;
0 commit comments