[英]angularjs save html from textarea
這是我的HTML:
<div ng-if="!item.edit>
<div class='door-description' ng-bind-html="item.Description"></div>
<div class='door-softvalues' ng-bind-html="item.SoftValues" ng-if="item.IsConfiguration"></div>
</div>
<div ng-if="item.edit">
<textarea elastic class='door-description' ng-bind-html="item.Description" ng-model="item.Description"></textarea>
<textarea elastic class='door-softvalues' ng-bind-html="item.SoftValues" ng-if="item.IsConfiguration" ng-model="item.SoftValues"></textarea>
</div>
因此,當我處於編輯模式並對textarea進行編輯時,換行符看起來不錯,但是當我保存文本並再次檢索時,它會使換行符松動。
這是編輯時的樣子:
這是不編輯時的樣子:
我仍然可以在編輯和不編輯之間切換,我將得到相同的結果。
不編輯時我該怎么做才能使換行出現?
您可以嘗試使用pre標簽嗎:
<pre class='door-description' ng-bind-html="item.Description"></pre>
只需將此樣式應用於您的元素:
white-space: pre;
你能這樣使用嗎?
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-sanitize.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<textarea elastic class='door-description' ng-bind-html="myText " ng-model="myText "></textarea>
</div>
<script>
var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope) {
$scope.myText = "My name is: <div><h1>John Doe</h1></div>";
});
</script>
也許這會工作。
它會像
My name is: <div><h1>John Doe</h1></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.