Skip to content

Commit

Permalink
fix(tooltip): leaking watchers on toggling
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chrisirhc committed Jan 17, 2014
1 parent 566ae73 commit fb20d63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ describe('tooltip', function() {
elm.trigger( 'mouseenter' );

ttScope = angular.element( elmBody.children()[1] ).isolateScope();
expect( ttScope.$parent ).toBe( elmScope );
expect( ttScope.$parent.$parent ).toBe( elmScope );

elm.trigger( 'mouseleave' );

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

ttScope = angular.element( elmBody.children()[1] ).isolateScope();
expect( ttScope.$parent ).toBe( elmScope );
expect( ttScope.$parent.$parent ).toBe( elmScope );

elm.trigger( 'mouseleave' );
}));
Expand Down Expand Up @@ -326,13 +326,13 @@ describe('tooltip', function() {
});

describe('cleanup', function () {
var elmBody, elm, elmScope, tooltipScope;
var elmBody, elm, elmScope, tooltipChildScope;

function inCache() {
var match = false;

angular.forEach(angular.element.cache, function (item) {
if (item.data && item.data.$isolateScope === tooltipScope) {
if (item.data && item.data.$scope === tooltipChildScope) {
match = true;
}
});
Expand All @@ -349,7 +349,7 @@ describe('tooltip', function() {
elm = elmBody.find('input');
elmScope = elm.scope();
elm.trigger('fooTrigger');
tooltipScope = elmScope.$$childTail;
tooltipChildScope = elmScope.$$childTail;
}));

it( 'should not contain a cached reference when visible', inject( function( $timeout ) {
Expand Down
4 changes: 3 additions & 1 deletion src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
if (tooltip) {
removeTooltip();
}
tooltip = tooltipLinker(scope, function () {});
// Make sure to use a new child scope every time as watchers leak into scope.
// If linked DOM is removed, watchers from that DOM isn't removed.
tooltip = tooltipLinker(scope.$new(), function () {});

// Get contents rendered into the tooltip
scope.$digest();
Expand Down

0 comments on commit fb20d63

Please sign in to comment.