0

I want to create tooltips in an ng-repeat with angular-tooltips. The content of the tooltips has to be dynamically. What I already have is something like this:

View:

<div ng-repeat="region in regions">
    <a tooltips tooltip-html="{{ myCtrl.generateTooltip(region) }}">HOVER</a>
</div>

Controller:

function generateTooltip(region) {
    // generate some html here
    var content = "<b>HELLO WORLD!</b>";
    return $sce.trustAsHtml( content );
}

The tooltip is shown and working, but I get the following error in console (which I don't want to see :-))

 Error: [$parse:syntax] Syntax Error: Token '<' not a primary
 expression at column 1 of the expression [<b>HELLO WORLD!</b>]
 starting at [<b>HELLO WORLD!</b>].
  1. What is wrong with my code?
  2. Is it possible to use a view as the tooltip instead of generating the HTML in the controller? There is an attribute tooltip-view, but I don't know how to pass my region variable to it.
6
  • 5
    you don't need the {{ }} here; the return value of the function isn't an expression that angular needs to evaluate. Commented Aug 28, 2015 at 15:06
  • If I remove the {{ }}, the content of the tooltip is "myCtrl.generateTooltip(region)" ;-) Commented Aug 28, 2015 at 15:08
  • Try the following (exactly): "'<b>HELLO WORLD!</b>'" (single quotes inside the double quotes). Commented Aug 28, 2015 at 15:10
  • @DavidM.Karr: Error: [$sce:unsafe] Attempting to use an unsafe value in a safe context., although I am using $sce.trustAsHtml()... Commented Aug 28, 2015 at 15:17
  • 3
    Seems like you didn't include angular-sanitize.js. Commented Aug 28, 2015 at 15:47

2 Answers 2

0

Someone else had a similar error resulting from a function running after the template was compiled by angular. Maybe this will set you in the right direction.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to include angular-sanitize.js which sanitize inputs by parsing the HTML into tokens. All safe tokens (from a whitelist) are then serialized back to properly escaped HTML string. This means that no unsafe input can make it into the returned string.

Comments

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.