[英]angularjs save html from textarea
this is my html: 这是我的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>
So the linebreak looks good when im in edit mode and do the edit to the textarea but when i save the text and retrieve it again it looses the linebreaks. 因此,当我处于编辑模式并对textarea进行编辑时,换行符看起来不错,但是当我保存文本并再次检索时,它会使换行符松动。
Here is what it looks like when editing: 这是编辑时的样子:
And here is what it looks like when not editing: 这是不编辑时的样子:
I can still toggle between edit and not editing and i will get the same result. 我仍然可以在编辑和不编辑之间切换,我将得到相同的结果。
What do i have to do to make the linebreaks appear when not editing? 不编辑时我该怎么做才能使换行出现?
您可以尝试使用pre标签吗:
<pre class='door-description' ng-bind-html="item.Description"></pre>
只需将此样式应用于您的元素:
white-space: pre;
Can you please use like this , 你能这样使用吗?
<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>
may be this will work . 也许这会工作。
It will give object like , 它会像
My name is: <div><h1>John Doe</h1></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.