This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -258,6 +258,7 @@ function $RouteProvider(){
258
258
259
259
if ( next && last && next . $route === last . $route
260
260
&& equals ( next . pathParams , last . pathParams ) && ! next . reloadOnSearch && ! forceReload ) {
261
+ next . scope = last . scope ;
261
262
$route . current = next ;
262
263
copy ( next . params , $routeParams ) ;
263
264
last . scope && last . scope . $emit ( '$routeUpdate' ) ;
Original file line number Diff line number Diff line change @@ -401,6 +401,43 @@ describe('$route', function() {
401
401
} ) ) ;
402
402
403
403
404
+ it ( 'should $destroy scope after update and reload' ,
405
+ inject ( function ( $route , $location , $rootScope ) {
406
+ // this is a regression of bug, where $route doesn't copy scope when only updating
407
+
408
+ var log = [ ] ;
409
+
410
+ function logger ( msg ) {
411
+ return function ( ) {
412
+ log . push ( msg ) ;
413
+ } ;
414
+ }
415
+
416
+ function createController ( name ) {
417
+ return function ( ) {
418
+ log . push ( 'init-' + name ) ;
419
+ this . $on ( '$destroy' , logger ( 'destroy-' + name ) ) ;
420
+ this . $on ( '$routeUpdate' , logger ( 'route-update' ) ) ;
421
+ } ;
422
+ }
423
+
424
+ $route . when ( '/foo' , { controller : createController ( 'foo' ) , reloadOnSearch : false } ) ;
425
+ $route . when ( '/bar' , { controller : createController ( 'bar' ) } ) ;
426
+
427
+ $location . url ( '/foo' ) ;
428
+ $rootScope . $digest ( ) ;
429
+ expect ( log ) . toEqual ( [ 'init-foo' ] ) ;
430
+
431
+ $location . search ( { q : 'some' } ) ;
432
+ $rootScope . $digest ( ) ;
433
+ expect ( log ) . toEqual ( [ 'init-foo' , 'route-update' ] ) ;
434
+
435
+ $location . url ( '/bar' ) ;
436
+ $rootScope . $digest ( ) ;
437
+ expect ( log ) . toEqual ( [ 'init-foo' , 'route-update' , 'destroy-foo' , 'init-bar' ] ) ;
438
+ } ) ) ;
439
+
440
+
404
441
describe ( 'reload' , function ( ) {
405
442
406
443
it ( 'should reload even if reloadOnSearch is false' ,
You can’t perform that action at this time.
0 commit comments