Home Ask Login Register

Developers Planet

Your answer is one click away!

user708683 February 2016

Angularjs : How to remove '\r\n' in my output

Why and how Angular add \r\n at the end of my text ? There's a way to remove them ? Also, i have other fields with a text but the \r\n are not there !!. Example of my json output :

{ description : "Description of the country USA \r\n"
id : 12
name : "USA\r\n"
continent : "North of America"

As you can see, the continent is also a text but i don't the \r\n at the end.


Shoeb February 2016

Add a filter to the place you bind that value. At that filter you slice of the last 4 characters of your var country [0].name, using the splice(); method.

Sumit Deshpande February 2016

Create angular filter say noCarriageReturn to remove \r\n as below on bind- JSFiddle For Reference - Demo

sampleApp.filter('noCarriageReturn', function() {
  return function(value) {
    return (!value) ? '' : value.replace(/(\r\n|\n|\r)/gm, "");

Hope this helps!

Post Status

Asked in February 2016
Viewed 2,524 times
Voted 11
Answered 2 times


Leave an answer

Quote of the day: live life