-1

I have tried to display HTML from database and in this HTML there are some Variables or scope for display, but that time it is considering it as a hard coded HTML. Please suggest me the solution for the same.

Response html

ptag {{ownerName}} ptag

browser output

{{ownerName}}

Solanki ram
  • 77
  • 2
  • 10

1 Answers1

0

In angular you have to tell the application that the HTML can be trusted.

https://docs.angularjs.org/api/ng/service/$sce

In the HTML you should set a html variable like:

<div ng-bind-html="htmlFromDB"></div>

in the controller you would use $sce

$scope.htmlFromDB = $sce.trustAsHtml(//somehtml)

This can be super dangerous, and add vulnerabilities to Cross site scripting. So make sure you know where that HTML came from!

Niles Tanner
  • 3,911
  • 2
  • 17
  • 29
  • its working for html but our question is we added html dynamically and that dynamic html contain ng-model ,ng-repeat, scope angular tag that not bind with our actual data because its run time added. – Solanki ram Sep 06 '16 at 15:13
  • you may want to check out this post: http://stackoverflow.com/questions/22536477/rendering-dynamic-htmlangularjs-content-content-after-ajax-call-in-angularjs. Using the answer there I was able to create a working example of dynamic html with angular binding: http://codepen.io/nilestanner/pen/RGNdkJ – Niles Tanner Sep 06 '16 at 15:46
  • 1
    i got solution refer link as below http://stackoverflow.com/questions/18157305/angularjs-compiling-dynamic-html-strings-from-database – Solanki ram Sep 06 '16 at 15:55