From 53f399b6e87906e662da2e6383261f2e2f4b8cb0 Mon Sep 17 00:00:00 2001 From: RobJacobs Date: Tue, 8 Sep 2015 14:46:25 -0400 Subject: [PATCH] fix(tooltip): isOpen to work with expressions The is-open attribute should work with expressions as well as model values Closes #4380 Fixes #4362 --- src/tooltip/test/tooltip.spec.js | 22 ++++++++++++++++++++++ src/tooltip/tooltip.js | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/tooltip/test/tooltip.spec.js b/src/tooltip/test/tooltip.spec.js index f0bd321a6d..d8d808f397 100644 --- a/src/tooltip/test/tooltip.spec.js +++ b/src/tooltip/test/tooltip.spec.js @@ -350,6 +350,28 @@ describe('tooltip', function() { }); }); + describe('with an is-open attribute expression', function() { + beforeEach(inject(function ($compile) { + scope.isOpen = false; + elm = $compile(angular.element( + 'Selector Text' + ))(scope); + elmScope = elm.scope(); + tooltipScope = elmScope.$$childTail; + scope.$digest(); + })); + + it('should show and hide with the expression', function() { + expect(tooltipScope.isOpen).toBe(false); + elmScope.isOpen = true; + elmScope.$digest(); + expect(tooltipScope.isOpen).toBe(true); + elmScope.isOpen = false; + elmScope.$digest(); + expect(tooltipScope.isOpen).toBe(false); + }); + }); + describe('with a trigger attribute', function() { var scope, elmBody, elm, elmScope; diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 4fbddcdc81..1c266ca7fd 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -221,7 +221,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position']) // And show the tooltip. ttScope.isOpen = true; - if (isOpenExp) { + if (isOpenExp && angular.isFunction(isOpenExp.assign)) { isOpenExp.assign(ttScope.origScope, ttScope.isOpen); } @@ -240,7 +240,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position']) // First things first: we don't show it anymore. ttScope.isOpen = false; - if (isOpenExp) { + if (isOpenExp && angular.isFunction(isOpenExp.assign)) { isOpenExp.assign(ttScope.origScope, ttScope.isOpen); }