1

I am injecting text into my Angular app with JSON objects. There is a "bio" section which requires HTML styling such as <br /> that way the text is not one chunk of unreadable text. I have tried trustAsHtml but it did not work for me. A working example would be best as I have read through Angular documentation and cannot get anyhting to work for me.

Help is greatly appreciated!

HTML w/ Angular JS

<div class="bio">
    {{exhibits[whichItem].bio}}
</div>

JSON

[
  {
    "name":"Name goes here",
    "bio":"First long block of text goes here then it needs a break <br /> and the second long block of text is here."
  }
]
1
  • How did it not work? Was there a console error from angular or did it not display? Can you give an example of how you are using the trustAsHtml? Commented Sep 26, 2017 at 19:03

2 Answers 2

1

you have to add 'ngSanitize' module as dependency also you have to include corresponding script :

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-sanitize.js"></script>

then use ng-bind-html

<div class="bio" ng-bind-html="exhibits[whichItem].bio">

</div>

if you don't use ngSanitize module , it will give you error for ng-bind-html

You can refer here

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

1 Comment

This did it! At first I couldn't get it to work, then I remembered I had to call it in angular.module. You really helped me out big time, and I am really grateful.
0

This

<div class="bio"ng-bind-html=exhibits[whichItem].bio>

</div>

Will probably do the trick.

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.