3

I am using angular treeview directive to show treeview. I am unable to render html.
for eg. B is showing as <b>B</b>.

here is the fiddle fiddle

i have used ng-html-bind for html rendering many times, but its not working here.

Community
  • 1
  • 1

2 Answers2

4

As ng-bind-html-unsafe has been deprecated now, you will need to use $sce.trustAsHtml. There is a nice article to understand what $sce is.

For quick reference you can also refer to stackoverflow question.

Community
  • 1
  • 1
Vaibhav Jain
  • 33,887
  • 46
  • 110
  • 163
  • but how to use this with directive? http://ngmodules.org/modules/angular.treeview there is no option for using ng-bind-html-unsafe or any other – devesh singhal May 22 '14 at 10:35
  • There is angular version 1.0.6 used in fiddle. I don't think angular has $sce since that time. – gorpacrate May 22 '14 at 11:11
  • oops , @gorpacrate : Nice catch. I was trying to modifying the fiddle, but no avail. You mentioned the reason. Thanks. – Vaibhav Jain May 22 '14 at 11:14
1

As it looks in treeview's code, by default you can't.

But you can modify it's code (example for minified version), change

<span data-ng-class="node.selected" data-ng-click="'+a+'.selectNodeLabel(node)">{{node.'+e+'}}</span>

to

<span data-ng-class="node.selected" data-ng-click="'+a+'.selectNodeLabel(node)" ng-bind-html-unsafe="node.'+e+'">

Don't forget to add ngSanitize module to your app: https://docs.angularjs.org/api/ngSanitize

Upd: Here is updated fiddle http://jsfiddle.net/vL4TJ/76/

gorpacrate
  • 5,109
  • 3
  • 21
  • 18