uib-tooltip-html is broken
Receive parse error on page load when trying to use uib-tooltip-html.
For example: uib-tooltip-html="Some text"
leads to:
Error: [$parse:syntax] Syntax Error: Token 'text' is an unexpected token at column 6 of the expression [Some text] starting at [text].
http://errors.angularjs.org/1.4.1/$parse/syntax?p0=text&p1=is%20an%20unexpected%20token&p2=6&p3=Some%20text&p4=text
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.js:68:12
at Object.AST.throwError (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.js:12865:11)
at Object.AST.ast (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.js:12635:12)
at Object.ASTCompiler.compile (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.js:13084:31)
at Parser.parse (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.js:13933:29)
at $parse (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.js:14057:39)
at link (https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js:5023:56)
at invokeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.js:8642:9)
at nodeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.js:8142:11)
at compositeLinkFn (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.js:7534:13) <p style="margin-top: 5em;" uib-tooltip-html="Some text">
Here is a plunkr link: http://plnkr.co/edit/vhqTJRrCyxBxkU0p6BS0
You have to wrap it in an html element: http://plnkr.co/edit/A1TBsU938PNfuD01s4n6?p=preview
@cavanm, in the future, please do not use the issues forum for support related requests. Rather, please follow the instructions here. The issues forum is reserved for bugs. Thanks.
Thank you @wesleycho!
The issue was actually that I was using uib-tooltip-html="{{myVar}}" rather than uib-tooltip-html="myVar". Your example helped me figure it out. You may want to add an uib-tooltip-html example to the documentation to make the usage clearer for others.
Thanks again. You quick response saved me having to waste a day finding another solution when ui-bootstrap actually solved my problem perfectly.
@icfantv I used the issues forum because I thought I had found a bug. It turns out I was using it wrong, but if I had known that I wouldn't have had an issue, would I?
That's a valid request - we actually are in the midst of work to update our documentation, so we intend on getting to the tooltip and making sure each feature has a working example.
@cavanm, it is documented so your attitude is not appreciated. We are all volunteers here and you might be surprised that the bulk of the issues people report are actually user error. Now, whether or not that's due to docs that aren't 100% crystal clear is up for discussion. What is not up for discussion is that the bulk of the people who do report issues, don't read our site to see how to either receive help or to report issues. You would be wise to keep this in mind for the future.
Dear @icfantv, I am sorry to have offended. I read the documentation available at https://angular-ui.github.io/bootstrap/ and saw that the only description of the functionality of uib-tooltip-html was this:
uib-tooltip-htmltakes whatever HTML is provided and displays it in a tooltip; The user is responsible for ensuring the content is safe to put into the DOM!
Seeing as how I had the uib-tooltip working perfectly using the uib-tooltip="{{content}}" notation I naively assumed the proper way to use the uib-tooltip-html function was similar and in the process, unfortunately, I made an ass out of you and me.
Thinking that I had an opportunity to get involved, I read the instructions found at https://github.com/angular-ui/bootstrap/blob/master/CONTRIBUTING.md#you-think-youve-found-a-bug, and followed them to created a use case on plinkr that demonstrated the issue as I understood it - all the while not realizing my simple, ignorant mistake.
Please accept my sincerest apologies and do realize that the reason I chose to submit an issue was that I know that opensource projects depend on the efforts of unpaid volunteers in order to develop, maintain, and even find existing bugs in the products they create; and we all have our parts to play.
Yours truly, with deepest regards @cavanm
Thank you for your cogent response. As Wes indicated, we're in the process of reprocessing the docs so hopefully it will be more clear moving forward.
@icfantv Actually, before 1.4 I had code like:
data-tooltip-html-unsafe="foo text <strong>{{dashboard.public? 'private': 'public'}}</strong>"
and it was working fine, this is not the case with tooltip-html anymore so from user perspective it looks like a bug because functionality changed significantly.
It is not a significant breaking change - one just needs to wrap it in an element. This is due to how $sce works.
I'm adding this cause it took me a while to figure it out. Not working:
uib-tooltip-html="{{::scopeVar | someFilterNotManadatory}}">
Working (notice the single quote)
uib-tooltip-html="'<html-tag>{{::scopeVar | someFilterNotManadatory}}</html-tag>'">
Working (single quote without wrapping tag)
uib-tooltip-html="'
It is not a significant breaking change - one just needs to wrap it in an element. This is due to how $sce works.
I disagree with this point as I use cell tooltips which works fine on previous version and do not works now. Wrap this data is complicated enough in this case.
Garbage. $sce doesn't need content to be wrapped in an html tag. Pull your head in and take a bug report ffs, even if it is from vague documentation. Its not a personal attack, don't respond like it was.. Fact is that using double brace literal expressions don't work in your directive for uib-tooltip-html if the expression evaluates to having a tag starting it your directive freaks out. its using angular values so its fine, that just needs to be pointed out. (using myVar instead of {{myvar}})
@rnnzdave, hey, please take it down a notch. There are other, more productive/conducive ways to communicate. Abusive language and behavior will not be tolerated. Thank you.
I have to agree with the non-Angular-UI devs here. The "new" way of doing html tooltips is very counter-intuitive and not well documented.
This does not work:
<span uib-tooltip-html="<p>{{somevar}}</p>">Hover</span>
This does work (notice single quotes):
<span uib-tooltip-html="'<p>{{somevar}}</p>'">Hover</span>
What the heck? Isn't that completely counter to the little symbol in the documentation that says "This setting expects an angular expression instead of a literal string." And yet, passing in a literal string works. How was I ever going to figure that out? It is documented nowhere and is an anti-pattern. Any particular reason the directive can't just handle it without quotes?
It is that way because if one is to use html, one needs to whitelist it via $sce & including ngSanitize. This is just how Angular works with its security context, and we make use of this standard in order to err on the side of security.
Unless someone can demonstrate why we shouldn't err on that side here, I believe there is nothing left to change here.
Why is uib-tooltip-html="<p>{{somevar}}</p>" considered not secure, but uib-tooltip-html="'<p>{{somevar}}</p>'" is considered secure?
From the directive's perspective, one is a string, the other is a string with quotes around it.
I just ran into this issue myself. The documentation remains unclear. Is there a reason why it hasn't been updated to point out that it requires a quoted string as input? Seems like a simple solution.
@jcwood, please feel free to submit a PR.
@icfantv I submitted a PR to address this