2

I am using the ng2-bootstrap tooltip Plugin for my angular 2 application. I want to add the tooltip attribute if a have defined a tooltip string in a shared file. To accomplish, I thought that the following line would work:

<label [attr.tooltip]="translations['artist-tooltip']">....</label>

This doesn't work however, if I hardcode the line however a tooltip does appear.

<label tooltip="custom string">....</label>

This is strange, because translations['artist-tooltip'] does return a string. If I inspect my element I can see that the HTML is exactly as expected. If I would implement something like:

<label *ngIf="translations['artist-tooltip']" tooltip="translations['artist-tooltip']">...</label>

I would get the desired result, however now the output field isn't shown if a tooltip string isn't defined, and that is not what I want. Does anybody know what is going wrong?

1
  • Sounds like a timing issue, like the bound value is read by bootstrap before Angular actually assigned it and then later assigned values are ignored. Commented May 30, 2016 at 14:17

2 Answers 2

1

Please try

<label tooltip=" " [attr.tooltip]="translations['artist-tooltip']">

or

<label tooltip="{{translations['artist-tooltip']}}">
Sign up to request clarification or add additional context in comments.

7 Comments

The first option only shows the empty tooltip (but at least it shows one), the second does work, the only problem is that it also shows an empty tooltip if there isn't a translation defined.
I assume you forgot one bracket in your second suggestion?
Thanks, already removed it. This confirms my suspicion about timing. *ngIf seems to be the only proper way then.
Cheers Angular guru Gunter, your first suggestion worked for async data from an *ngFor: tooltipNotes=" " [attr.tooltipNotes]="getRecord(record)?.Notes"
Glad to hear :) Thanks for the feedback!
|
0

Please try

<label data-tooltip [attr.data-tooltip]="translations['artist-tooltip']">

for me work

obs: Angular 2

1 Comment

an explanation would be nice to go with this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.