Skip to content

Commit fb20d63

Browse files
committed
fix(tooltip): leaking watchers on toggling
Make sure to use a new child scope every time as watchers leak into scope. If linked DOM is removed, watchers from directives in that DOM aren't removed. Regression from angular-ui#1455
1 parent 566ae73 commit fb20d63

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/tooltip/test/tooltip.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ describe('tooltip', function() {
148148
elm.trigger( 'mouseenter' );
149149

150150
ttScope = angular.element( elmBody.children()[1] ).isolateScope();
151-
expect( ttScope.$parent ).toBe( elmScope );
151+
expect( ttScope.$parent.$parent ).toBe( elmScope );
152152

153153
elm.trigger( 'mouseleave' );
154154

155155
// After leaving and coming back, the scope's parent should be the same
156156
elm.trigger( 'mouseenter' );
157157

158158
ttScope = angular.element( elmBody.children()[1] ).isolateScope();
159-
expect( ttScope.$parent ).toBe( elmScope );
159+
expect( ttScope.$parent.$parent ).toBe( elmScope );
160160

161161
elm.trigger( 'mouseleave' );
162162
}));
@@ -326,13 +326,13 @@ describe('tooltip', function() {
326326
});
327327

328328
describe('cleanup', function () {
329-
var elmBody, elm, elmScope, tooltipScope;
329+
var elmBody, elm, elmScope, tooltipChildScope;
330330

331331
function inCache() {
332332
var match = false;
333333

334334
angular.forEach(angular.element.cache, function (item) {
335-
if (item.data && item.data.$isolateScope === tooltipScope) {
335+
if (item.data && item.data.$scope === tooltipChildScope) {
336336
match = true;
337337
}
338338
});
@@ -349,7 +349,7 @@ describe('tooltip', function() {
349349
elm = elmBody.find('input');
350350
elmScope = elm.scope();
351351
elm.trigger('fooTrigger');
352-
tooltipScope = elmScope.$$childTail;
352+
tooltipChildScope = elmScope.$$childTail;
353353
}));
354354

355355
it( 'should not contain a cached reference when visible', inject( function( $timeout ) {

src/tooltip/tooltip.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
262262
if (tooltip) {
263263
removeTooltip();
264264
}
265-
tooltip = tooltipLinker(scope, function () {});
265+
// Make sure to use a new child scope every time as watchers leak into scope.
266+
// If linked DOM is removed, watchers from that DOM isn't removed.
267+
tooltip = tooltipLinker(scope.$new(), function () {});
266268

267269
// Get contents rendered into the tooltip
268270
scope.$digest();

0 commit comments

Comments
 (0)