Alex Reynolds
Alex Reynolds

Reputation: 96937

Angularjs UI bootstrap popover having difficulty with rendering HTML

I have an AngularJS (v1.4.7) directive that uses AngularJS-UI (v0.14.3).

Inside the directive, I have a popover that works if I only use uib-tooltip, e.g.:

...
directiveContent += '<span uib-popover="Some normal text">Popover!</span>';
...

The directive's popover fails once I switch this to uib-tooltip-html:

...
directiveContent += '<span uib-popover-html="Some <b>bold</b> text!">Popover!</span>';
...

The parse error that comes up relates to the link: part of directive, wherein I watch if the content of the directive changes, and I then re-compile the contents:

scope.$watch('content', function(value) {
    var span = angular.element(element.find('span')[1]);
    span.html(value);
    $compile(span)(scope);  // <--- SOME ERROR OCCURS HERE
});

I compile in order to bind elements to event handlers.

Here is the specific $parse error:

angular.js:12477 Error: [$parse:syntax] http://errors.angularjs.org/1.4.7/$parse/syntax?p0=%2F&p1=not%20a%20primary…expression&p2=14&p3=Some%20%3Cb%3Ebold%3C%2Fb%3E%20text!&p4=%2Fb%3E%20text!
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:6:416
at Object.s.throwError (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:209:339)
at Object.s.primary (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:206:337)
at Object.s.unary (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:205:503)
at Object.s.multiplicative (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:205:249)
at Object.s.additive (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:205:76)
at Object.s.relational (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:205:19)
at Object.s.equality (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:204:241)
at Object.s.logicalAND (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:204:94)
at Object.s.logicalOR (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:203:458)
at Object.s.ternary (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:203:253)
at Object.s.assignment (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:203:107) <span popover-append-to-body="true" popover-animation="true" uib-popover-html="Some <b>(anonymous function) @ angular.js:12477(anonymous function) @ angular.js:9246aa @ angular.js:8791K @ angular.js:8289g @ angular.js:7680g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684(anonymous function) @ angular.js:7555(anonymous function) @ my-directive.js:57n.$digest @ angular.js:15826n.$apply @ angular.js:16097h @ angular.js:10546K @ angular.js:10744e @ angular.js:10695E @ angular.js:10734e @ angular.js:5507(anonymous function) @ angular.js:5784

How could I go about fixing this?

Upvotes: 0

Views: 690

Answers (2)

Rob J
Rob J

Reputation: 6629

See this issue on the angular-ui-bootstrap repo. The recommended approach when using tooltip/popover-html is to wrap the content in quotes:

 '<span uib-popover-html="\'<span>Some <b>bold</b> text!</span>\'">Popover!</span>'

Upvotes: 2

johan
johan

Reputation: 1012

I use the following code to add tooltips, maybe it'll work for you:

<inactive_icon></inactive_icon>    

angular.element("inactive_icon")
       .empty()
       .replaceWith($compile('<i class="fa fa-minus-circle text-danger" tooltip-placement="right" uib-tooltip="File Inactive"></i>')($scope));

Upvotes: 0

Related Questions