-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}}

1 Answer 1

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!

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

3 Comments

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.
you may want to check out this post: stackoverflow.com/questions/22536477/…. Using the answer there I was able to create a working example of dynamic html with angular binding: codepen.io/nilestanner/pen/RGNdkJ
i got solution refer link as below stackoverflow.com/questions/18157305/…

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.