diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 9501f50051..a30d2d229e 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -143,7 +143,27 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s var ttScope = scope.$new(true); var repositionScheduled = false; var isOpenExp = angular.isDefined(attrs[prefix + 'IsOpen']) ? $parse(attrs[prefix + 'IsOpen']) : false; - + var contentExpVal; + var contentExpGetter; + var contentExpGetterStartWatch; + var contentExpGetterStopWatch; + + if(options.useContentExp){ + contentExpGetter = $parse(attrs[type]); + + contentExpGetterStartWatch = function(){ + if(contentExpGetterStopWatch){ + contentExpGetterStopWatch(); + } + contentExpGetterStopWatch = scope.$watch(contentExpGetter,function(val){ + contentExpVal = val; + if (!val && ttScope.isOpen) { + hide(); + } + }); + }; + } + var positionTooltip = function() { // check if tooltip exists and is not empty if (!tooltip || !tooltip.html()) { return; } @@ -231,7 +251,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s } // Don't show empty tooltips. - if (!(options.useContentExp ? ttScope.contentExp() : ttScope.content)) { + if (!(options.useContentExp ? contentExpGetter(scope) : ttScope.content)) { return angular.noop; } @@ -296,11 +316,9 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s }); if (options.useContentExp) { - tooltipLinkedScope.$watch('contentExp()', function(val) { - if (!val && ttScope.isOpen) { - hide(); - } - }); + if(!contentExpGetterStopWatch){ + contentExpGetterStartWatch(); + } tooltipLinkedScope.$watch(function() { if (!repositionScheduled) { @@ -323,6 +341,10 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s tooltip.remove(); tooltip = null; } + if(contentExpGetterStopWatch){ + contentExpGetterStopWatch(); + contentExpGetterStopWatch = null; + } if (tooltipLinkedScope) { tooltipLinkedScope.$destroy(); tooltipLinkedScope = null; @@ -336,7 +358,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s } ttScope.contentExp = function() { - return scope.$eval(attrs[type]); + return contentExpVal; }; /**