Only read this if prompted dynamically
i.e. <div tooltip={{ obj.somePropertyThatMayChange }} ...></div>
I had a problem with dynamic tooltips that were not always updated in the view. For example, I was doing something like this:
It does not work consistently
<div ng-repeat="person in people"> <span data-toggle="tooltip" data-placement="top" title="{{ person.tooltip }}"> {{ person.name }} </span> </div>
And activate it like this:
$timeout(function() { $(document).tooltip({ selector: '[data-toggle="tooltip"]'}); }, 1500)
However, since my users array would change my tooltips, it was not always updated. I tried all the corrections in this thread, and others - with no luck. It seems that a glitch occurred only in 5% of cases, and it was almost impossible to repeat.
Unfortunately, these tips are critical to my project, and showing the wrong tip can be very bad.
What seemed like a problem
Bootstrap copied the value of the title property to the new data-original-title attribute and removed the title property (sometimes) when I activated toooltips. However, when my title={{ person.tooltip }} changes, the new value will not always be updated in the data-original-title property. I tried disabling the tooltips and reactivating them, destroying them, binding to this property directly ... that's it. However, each of them either did not work or created new problems; such as the title and data-original-title attributes, which are deleted and unrelated to my object.
What worked
Perhaps the ugliest code I've ever expressed, but solved this small but significant issue for me. I run this code every time the tooltip is updated with new data:
$timeout(function() { $('[data-toggle="tooltip"]').each(function(index) {
What essentially happens here:
- Wait a while (1500 ms) to complete the digest cycle and update the
title . - If there is a
title property that is not empty (i.e. it has changed), copy it to the data-original-title property so that it is picked up by the Bootstrap tools. - Reactivating tooltips
Hope this long answer helps someone who may have struggled just like me.
Matt May 29 '17 at 12:21 2017-05-29 12:21
source share