AngularJS:写入和多线从textarea的阅读 [英] AngularJS: Writing to and Reading from textarea with multilines
问题描述
我简直不敢相信,为什么我找不到任何这个主题...
我得到了与假设姓氏(输入),姓名(输入),描述(textarea的,因为我想提供几行)的形式。让我们开始创建一个新的对象:
I can't believe why I can't find anything to this topic ... I got a form with let's say lastname (input), firstname (input), description (textarea as I want provide several lines). Let's start with the creation of a new object:
好吧,你输入喜欢的东西
Okay, you type something in like
名字:狐狸
姓:彼得
说明:
what can I say ..
well I'm THE guy
bye
这来到我的Java Spring MVC的后端控制器为我能说什么.. \\ N阱我就是那个\\ n \\ nbye
这是罚款,我能确定其中,换行符。
This arrives at my Java Spring MVC Backend Controller as what can I say ..\nwell I'm THE guy\n\nbye
which is fine as I can determine where line breaks are.
所以,现在我想编辑该对象。因此,我想读存储数据,并把它的形式。在Serverside集团现在我编辑的说明文字,让我取代了 \\ n
与< BR>
让我有HTML休息。
So, now I want to edit this object. Thus I want to read the stored data and put it in the form. On Serverside I now edited the description text so that I replaced the \n
with <br>
so that I have HTML breaks.
现在我用角的sanitize(ngSanitize依赖),并使用该指令 NG-绑定-HTML =my.nice.description
Now I use angular-sanitize (ngSanitize dependency) and use the directive ng-bind-html="my.nice.description"
如果我用这一个DIV,一切工作正常,HTML获取呈现,我得到我的休息时间。所以这完美的作品:
If I use this on a DIV, everything works fine, HTML gets rendered and I get my breaks. So this works perfectly:
<span ng-bind-html="my.nice.description"></span>
或以下之一:
<div ng-bind-html="my.nice.description"></div>
<p ng-bind-html="my.nice.description"></p>
但是,当我想(重新)填写我的形式,使用户可以编辑自己的previous投入,我还是用一个textarea。像这样的:
BUT as I want to (re)fill my form so the user can edit his previous input, I still use a textarea. Like this:
<textarea ng-bind-html="my.nice.description"></textarea>
,这不以任何方式工作。这意味着我得到结果的在我的文字,未渲染的。
And this does NOT work in any way. Which means that I get
's in my text, unrendered.
虽然这似乎是一个正常的ridicilous任务。这是一个简单的多行框的形式,所以我想我写的几行,我想读他们,我想编辑它们。
由于我而后端的家伙,不是很熟悉HTML和AngularJS我希望,我只是使用了错误的HTML元素或这样的事情...也许有人可以帮我吗?这是令人沮丧:(
Though this seems like a ridicilous normal task. It's a form with a simple multiline box, so I want to write my several lines and I want to read them and I want to edit them. As I am rather a backend guy and not very familiar with HTML and AngularJS I hope that I'm just using the wrong html element or something like this ... Maybe someone can help me out? It's frustrating :(
在此先感谢,我想和希望这不是一个真正的硬任务:X
Thanks in advance and I guess and hope this is not a real hard task :x
推荐答案
&LT; textarea的&GT;
元素的不能包含其他元素(在你的案件,&LT; BR&GT;
的)。他们是独立的。你必须转换成可变返回 - 从含服务器 - &LT; BR&GT;
的返回到 \\ n
的,反之亦然来回。您可以使用一个角指令处理,对你。
<textarea>
elements cannot contain other elements (in your case, <br>
's). They are standalone. You'll have to convert the variable-returned-from-server-containing-<br>
's back to \n
's, and vice versa back and forth. You can use an angular directive that handles that for you.
这篇关于AngularJS:写入和多线从textarea的阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!