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

fix(tooltip): make sure tooltip scope is evicted from cache. #486

Closed
wants to merge 1 commit into from
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
40 changes: 40 additions & 0 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,46 @@ describe('tooltip', function() {
}));
});

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

function inCache() {
var match = false;

angular.forEach(angular.element.cache, function (item) {
if (item.data && item.data.$scope === tooltipScope) {
match = true;
}
});

return match;
}

beforeEach(inject(function ( $compile, $rootScope ) {
elmBody = angular.element('<div><input tooltip="Hello!" tooltip-trigger="fooTrigger" /></div>');

$compile(elmBody)($rootScope);
$rootScope.$apply();

elm = elmBody.find('input');
elmScope = elm.scope();
tooltipScope = elmScope.$$childTail;
}));

it( 'should not contain a cached reference', function() {
expect( inCache() ).toBeTruthy();
elmScope.$destroy();
expect( inCache() ).toBeFalsy();
});

it( 'should not contain a cached reference when visible', inject( function( $timeout ) {
expect( inCache() ).toBeTruthy();
elm.trigger('fooTrigger');
elmScope.$destroy();
$timeout.flush();
expect( inCache() ).toBeFalsy();
}));
});
});

describe('tooltipWithDifferentSymbols', function() {
Expand Down
9 changes: 5 additions & 4 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,13 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
}
});
}

// if this trigger element is destroyed while the tooltip is open, we
// need to close the tooltip.
scope.$on('$destroy', function closeTooltipOnDestroy () {

// Make sure tooltip is destroyed and removed.
scope.$on('$destroy', function onDestroyTooltip() {
if ( scope.tt_isOpen ) {
hide();
} else {
tooltip.remove();
}
});
}
Expand Down