Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the text with Line Breaks

Tags:

html

angularjs

enter image description here

I need to display the text with the line breaks, this is the script

<script>
    var app = angular.module('MyApp', []);
    app.controller('Ctrl', function ($scope) {
        console.log('Controller is executed');
        $scope.btnClick = function () {
            console.log($scope.desc);
        }
        $scope.ShowData = function () {
            $scope.text = $scope.desc;
        }
    });
</script>

And this is the html code

<body ng-controller="Ctrl">
<form>
    <textarea ng-model="desc" cols="105" rows="15"></textarea>
    <button ng-click="btnClick()">Submit</button>
    <button ng-click="ShowData()">Show</button>
</form>
<div ng-bind="text"></div>

like image 640
Omkar Dixit Avatar asked Mar 23 '17 10:03

Omkar Dixit


People also ask

How do you display a label with text with line breaks?

You can wrap your asp label in a pre tag, and it will display with whatever line breaks are set from the code behind. Show activity on this post. You can also use <br/> where you want to break the text.

How do you insert a line break in text?

Press ALT+ENTER to insert the line break.

How do I show line break in HTML?

The <br> tag inserts a single line break. The <br> tag is useful for writing addresses or poems. The <br> tag is an empty tag which means that it has no end tag.

How do you show new line characters?

This character is commonly known as the 'Line Feed' or 'Newline Character'. CR (character : \r, Unicode : U+000D, ASCII : 13, hex : 0x0d) : This is simply the 'r' character.


2 Answers

Try render text inside <pre></pre> tag instead of <div>. Or use style="white-space:pre-wrap;" on your div.

like image 196
Alex Frolov Avatar answered Oct 16 '22 15:10

Alex Frolov


Just add this to your styles, this works for me

white-space: pre-wrap

HTML

<p class="text-style">{{product?.description}}</p>

CSS

.text-style {
    white-space: pre-wrap;
}

By this text in <textarea>can be display as it's in there with spaces and line brakes

like image 36
Akitha_MJ Avatar answered Oct 16 '22 15:10

Akitha_MJ