简体   繁体   English

Textarea预览

[英]Textarea preview

I have a problem regarding textarea and text previewing. 我有关于textarea和文本预览的问题。 It doesn't recognize Enter button as a newline character. 它不会将Enter按钮识别为换行符。 Any ideas how to make this previewing correctly? 有任何想法如何正确预览?

在此输入图像描述

EDIT : 编辑:

在此输入图像描述

I want this text automatically change line when it's not fitting instead of h-scroll. 我希望这个文本在不适合而不是h-scroll时自动改变行。

Answer : 答案:

pre {
 white-space: pre-wrap;       /* css-3 */
 white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
 white-space: -pre-wrap;      /* Opera 4-6 */
 white-space: -o-pre-wrap;    /* Opera 7 */
 word-wrap: break-word;       /* Internet Explorer 5.5+ */
}

You can use <pre> tag while printing text from textarea it will reflect all your new lines as it is entered text in textarea 您可以在从textarea打印文本时使用<pre>标记它将反映所有新行,因为它是在textarea输入的文本

Just use <pre> before content.eg 只需在content.eg之前使用<pre>

<pre> Text Content From text Area</pre>

http://plnkr.co/edit/gZM1173PNweJzcBEutTw?p=preview http://plnkr.co/edit/gZM1173PNweJzcBEutTw?p=preview

You need to use ngSanitize and allow you parameter to accept html entry with $sce.trustAsHtml(); 您需要使用ngSanitize并允许参数接受带有$ sce.trustAsHtml()的html条目;

html HTML

<textarea ng-model="text" ng-change="change()"></textarea>
<p ng-bind-html='text'></p>

js JS

$scope.change = function(){ 

    $scope.text = $sce.trustAsHtml($scope.text);
}

css CSS

{white-space: pre}

You'll be able to render and save your text with newline 您将能够使用换行符渲染和保存文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM