0

I'm trying to print out content in an object, and some of those properties have
tags in them which is why I can't just randomly create new elements in js because I don't know which properties will have
tags. But they're not rendering in my browser. I feel like I'm missing a very simple concept here... An example is provided below

JSFiddle: http://jsfiddle.net/tvzgypd6/3/

Here is just an example of an object that won't display properly when I use ng-repeat in angular

$scope.objs = [
    {a : 'test 1 <br> test 1'},
    {a : 'test 2 '},
    {a : 'test 3'},
    {a : "test 4 \n test 4"},
    {a : 'test 5 \n test 5'},
]
abcf
  • 685
  • 2
  • 10
  • 25

2 Answers2

1

you can achieve it through CSS:

p {
    white-space: pre;
}

here a fork of your fiddle: http://jsfiddle.net/em0r3krw/

Simon Wicki
  • 4,029
  • 4
  • 22
  • 25
0

In order to show html you should use ng-bind-html and ng-sanitize:

angular.module('test', ['ngSanitize'])
<li ng-repeat="obj in objs">
    <p ng-bind-html="obj.a"></p>
</li>

In html \n won't actually add a new line. So you should use white-space: pre; as pointed out by zwacky:

p {
    white-space: pre;
}

JsFiddle

Wayne Ellery
  • 7,888
  • 1
  • 28
  • 45