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

Commit 13df1c9

Browse files
cvnwesleycho
authored andcommitted
fix(tooltip): update tooltip placement dynamically
Closes #3980 Fixes #3978
1 parent 632aa82 commit 13df1c9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/tooltip/test/tooltip.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ describe('tooltip', function() {
6868
expect( tooltipScope.placement ).toBe( 'bottom' );
6969
}));
7070

71+
it('should update placement dynamically', inject( function( $compile, $timeout ) {
72+
scope.place = 'bottom';
73+
elm = $compile( angular.element(
74+
'<span tooltip="tooltip text" tooltip-placement="{{place}}">Selector Text</span>'
75+
) )( scope );
76+
scope.$apply();
77+
elmScope = elm.scope();
78+
tooltipScope = elmScope.$$childTail;
79+
80+
elm.trigger( 'mouseenter' );
81+
expect( tooltipScope.placement ).toBe( 'bottom' );
82+
83+
scope.place = 'right';
84+
scope.$digest();
85+
$timeout.flush();
86+
expect(tooltipScope.placement).toBe( 'right' );
87+
}));
88+
7189
it('should work inside an ngRepeat', inject( function( $compile ) {
7290

7391
elm = $compile( angular.element(

src/tooltip/tooltip.js

+9
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
307307
positionTooltipAsync();
308308
});
309309

310+
attrs.$observe( prefix + 'Placement', function () {
311+
if (ttScope.isOpen) {
312+
$timeout(function () {
313+
prepPlacement();
314+
show()();
315+
}, 0, false);
316+
}
317+
});
318+
310319
function prepPopupClass() {
311320
ttScope.popupClass = attrs[prefix + 'Class'];
312321
}

0 commit comments

Comments
 (0)