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.

1
  • What version of Angular JS are you using. In Angular 1.2.0 ng-bind-html-unsafe has been deprecated. Commented May 22, 2014 at 9:23

2 Answers 2

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.

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

3 Comments

but how to use this with directive? ngmodules.org/modules/angular.treeview there is no option for using ng-bind-html-unsafe or any other
There is angular version 1.0.6 used in fiddle. I don't think angular has $sce since that time.
oops , @gorpacrate : Nice catch. I was trying to modifying the fiddle, but no avail. You mentioned the reason. Thanks.
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/

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.