简体   繁体   English

与Angular 1的双向数据绑定

[英]two way data binding with Angular 1

Basically what my problem is that I have a input field and text area like so: 基本上,我的问题是我有一个输入字段和文本区域,如下所示:

<input type="text" placeholder="Your URL*" id="userURL" ng-model = "usermodel"/><br />
<textarea id="final">{{usermodel}}</textarea><br />

So my problem is that text will be manipulated via controller, and I want the user to be able to type into the field WITHOUT the textarea refreshing. 所以我的问题是文本将通过控制器进行操作,我希望用户能够在不刷新文本区域的情况下键入字段。

For example: 例如:

controller: {
textareaoutoutput = "hi ..... How are you";}

textarea: hi {{usermodel}} how are you? <br>
input field: john

BUT when I type into the field, "Hi how are you" gets removed, and only the text field input is shown. 但是,当我在该字段中键入内容时,“嗨,你好吗”将被删除,仅显示文本字段输入。 I would like it so that the "Hi how are you" is fixed and will not change while the user can enter and still see it add instantly. 我希望它是固定的,“嗨,你好吗?”不会改变,而用户可以进入并仍然看到它立即添加。

I hope that makes sense 我希望这是有道理的

inside controller : 内部控制器:

 $scope.textVal = " hi "+ $scope.usermodel + " how are you?" 

 <textarea id="final">{{textVal}}</textarea><br /> 

I hope you can understand it always try to function for the manipulate string 我希望您能理解它总是尝试为操纵字符串起作用

or 要么

 <textarea id="final">Hi {{usermodel}} how are you!</textarea><br /> 

hm, I am not sure if this will work. 嗯,我不确定这是否行得通。 the controller is going to output text to the text area, but I want the angular expression tags {{x}} to be in the middle of the the document will be outputting 控制器将文本输出到文本区域,但是我想将角度表达式标签{{x}}放在文档中间

Maybe this example will be better 也许这个例子会更好

textarea: 文字区域:

TEXTA + {{angular expression}} + TEXTB

is it possible to output data to text a and text b and have a user still add something to the {{x}} without refreshing the textarea 是否可以将数据输出到文本a和文本b并让用户仍然向{{x}}添加一些内容而不刷新文本区域

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

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