如何用换行符显示文本

如何用换行符显示文本

本文介绍了如何用换行符显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用换行符显示文本,这是脚本

 < 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>

这是html代码

 < body ng-controller =Ctrl> 
< form>
< button ng-click =btnClick()>提交< / button>
< button ng-click =ShowData()>显示< /按钮>
< / form>
< div ng-bind =text>< / div>


解决方案< pre>< / pre> 标记内而不是< div>
或在您的div上使用 style =white-space:pre-wrap;


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>
解决方案

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

这篇关于如何用换行符显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 16:42