Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

fix(tooltip): leaking watchers on toggling (WIP) #1601

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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