1

I'm building a inbox chat app in angularjs. Users type in their message in a textarea and their messages gets saved into the db. They can press enter while writing in the textarea to create line breaks (for long messages).

However when I retrieve the messages, all of the line breaks just show as single spaces. I cannot use
because the data I'm retrieving is in angularjs' interpolation brackets {{messageinfo.message}}.

How do I show the linebreaks a user types in?

Thanks

EDIT:

Answer solved here.

Preserve line breaks in angularjs

Community
  • 1
  • 1
user1424508
  • 3,231
  • 13
  • 40
  • 66
  • 1
    possible duplicate of [Preserve line breaks in angularjs](http://stackoverflow.com/questions/19684708/preserve-line-breaks-in-angularjs) – Stewie Dec 04 '13 at 09:02
  • 1
    This is not a duplicate, and does not work in this case, because textareas must be bound with ng-model and don't support ng-bind-html. There is nowhere to put
     tags.
    
    @user1424508, how did you get it to work?
    – erfling Jun 27 '14 at 22:04

1 Answers1

0

The issue is linebreaks in textareas aren't the same as html tags (\n vs <br />)

run a replace on it and wallah

replace(/\r?\n/g, '<br />');
Sterling Archer
  • 22,070
  • 18
  • 81
  • 118
  • i did that. That just makes all the spaces turn into
    text on the screen. For example if I wrote in the textarea hi bye it would output hi
    bye on the screen
    – user1424508 Dec 04 '13 at 09:13