I'm relatively new to angularjs. I'm trying to write a filter take a block of text and wrap certain words in an html tag, namely the link tag. The ultimate reason for wanting to do so is to enable ui-bootstrap tooltips on certain words, based on user input (for example, the search word or "key" might be entered via an input form field).
This is my filter (based on angular-ui 'highlight': https://github.com/angular-ui/ui-utils/blob/master/modules/highlight/highlight.js) --
.filter('annotate', function ($sce) {
return function (text, search) {
text = text.toString();
search = search.toString();
return text.replace(new RegExp(search,'gi'), '<a href="#" class="mycoolstyle" tooltip-placement="top" tooltip="test">$&</a>');
};
It works, in so far as the href and the class show up in the output. However, the attributes "tooltip-placement" and "tooltip" get filtered out. I would think this is an html filtering issue except it's letting href and class through.
The output html looks like:
<p ng-bind-html="contentStr | annotate:key" class="ng-binding">Hello World check out my <a href="#" class="mycoolstyle">foo</a> bar app</p>
jsFiddle: http://jsfiddle.net/petersg5/76WZf/
Also note I'm using 1.2.1 so there's no ng-bind-html-unsafe (thus the $sce).
Any ideas? I'm kinda stumped here.
Also, perhaps I'm going about this all wrong?