mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-20 04:11:51 +00:00
fix(route): $destroy scope after update and reload
When we update route (changing only search param, no route reload) and then reload (change to different route), it did not $destroy last scope.
This commit is contained in:
parent
d1e7a5394a
commit
b9001e9147
2 changed files with 38 additions and 0 deletions
|
|
@ -258,6 +258,7 @@ function $RouteProvider(){
|
||||||
|
|
||||||
if (next && last && next.$route === last.$route
|
if (next && last && next.$route === last.$route
|
||||||
&& equals(next.pathParams, last.pathParams) && !next.reloadOnSearch && !forceReload) {
|
&& equals(next.pathParams, last.pathParams) && !next.reloadOnSearch && !forceReload) {
|
||||||
|
next.scope = last.scope;
|
||||||
$route.current = next;
|
$route.current = next;
|
||||||
copy(next.params, $routeParams);
|
copy(next.params, $routeParams);
|
||||||
last.scope && last.scope.$emit('$routeUpdate');
|
last.scope && last.scope.$emit('$routeUpdate');
|
||||||
|
|
|
||||||
|
|
@ -401,6 +401,43 @@ describe('$route', function() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
it('should $destroy scope after update and reload',
|
||||||
|
inject(function($route, $location, $rootScope) {
|
||||||
|
// this is a regression of bug, where $route doesn't copy scope when only updating
|
||||||
|
|
||||||
|
var log = [];
|
||||||
|
|
||||||
|
function logger(msg) {
|
||||||
|
return function() {
|
||||||
|
log.push(msg);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function createController(name) {
|
||||||
|
return function() {
|
||||||
|
log.push('init-' + name);
|
||||||
|
this.$on('$destroy', logger('destroy-' + name));
|
||||||
|
this.$on('$routeUpdate', logger('route-update'));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
$route.when('/foo', {controller: createController('foo'), reloadOnSearch: false});
|
||||||
|
$route.when('/bar', {controller: createController('bar')});
|
||||||
|
|
||||||
|
$location.url('/foo');
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect(log).toEqual(['init-foo']);
|
||||||
|
|
||||||
|
$location.search({q: 'some'});
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect(log).toEqual(['init-foo', 'route-update']);
|
||||||
|
|
||||||
|
$location.url('/bar');
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect(log).toEqual(['init-foo', 'route-update', 'destroy-foo', 'init-bar']);
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
describe('reload', function() {
|
describe('reload', function() {
|
||||||
|
|
||||||
it('should reload even if reloadOnSearch is false',
|
it('should reload even if reloadOnSearch is false',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue