mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
fix(ngSwitch): don't leak when destroyed while not attached
The leak can occur when ngSwich is used inside ngRepeat or any other directive which is destroyed while its transcluded content (which includes ngSwitch) is not attached to the DOM. Refactor ngSwitch to use controller instead of storing data on compile node. This means that we don't need to clean up the jq data cache. Controller reference is released when the linking fn is released. Closes #1621
This commit is contained in:
committed by
Igor Minar
parent
1f8be1ca66
commit
89303fd2dc
@@ -90,4 +90,19 @@ describe('ngSwitch', function() {
|
||||
expect(child2).toBeDefined();
|
||||
expect(child2).not.toBe(child1);
|
||||
}));
|
||||
|
||||
|
||||
it('should not leak jq data when compiled but not attached to parent when parent is destroyed',
|
||||
inject(function($rootScope, $compile) {
|
||||
element = $compile(
|
||||
'<div ng-repeat="i in []">' +
|
||||
'<ng-switch on="url">' +
|
||||
'<div ng-switch-when="a">{{name}}</div>' +
|
||||
'</ng-switch>' +
|
||||
'</div>')($rootScope);
|
||||
$rootScope.$apply();
|
||||
|
||||
// element now contains only empty repeater. this element is dealocated by local afterEach.
|
||||
// afterwards a global afterEach will check for leaks in jq data cache object
|
||||
}));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user