0

I have a string with lots of " which i replace with an empty String and this works. But I also want to make a line break when a comma appears.

Already tried it with ('\n'), ('\r'), ('<br>'), ('<br/>') but nothing works. in my angular controller I have the string

self.msg = msg.replace(/"/gi, '').replace(/,/gi, '\n'); 
self.testAlerts = [{ type: 'success', msg: self.msg}];

I want to show this message in the alert box in my html

<div uib-alert ng-repeat="alert in testAlerts" type="{{alert.type}}" >{{alert.msg}}</div>

Why do the line breaks not work?

nolags
  • 633
  • 1
  • 11
  • 30

2 Answers2

1

Use ng-bind-html instead of interpolation:

<div uib-alert ng-repeat="alert in testAlerts" type="{{alert.type}}" ng-bind-html="alert.msg"></div>

Here's a plunkr for demonstration.

RamblinRose
  • 4,883
  • 2
  • 21
  • 33
0

If anybody from Angular world is happen to be here you can use [innerHTML] instead of [ng-bind-html] from @RamblinRose's answer

Or even, just add css white-space class

<div uib-alert ng-repeat="alert in testAlerts" style="white-space: pre-line;" type="{{alert.type}}" >{{alert.msg}}</div>
Josf
  • 776
  • 1
  • 8
  • 21