Omkar Dixit Omkar Dixit -4 years ago 99
HTML Question

How to show the text with Line Breaks

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>



Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download