不应该NG-绑定输入工作呢? [英] Shouldn't ng-bind work for input as well?
问题描述
我有点迷惑不解我
<input ng-bind="x.a * x.b" tabindex="-1" readonly/>
EX pression不工作。我不能使用 NG-模型
那里(如产品无L值),所以我盲目地切换到 NG-绑定
。我想,它并不因为搞笑HTML不一致的工作(使用值= XXX
而不是放置在元素文本的值)。所以,我切换到
expression not working. I can't use ng-model
there (as the product is no L-value), so I blindly switched to ng-bind
. I guess, it doesn't work because of the funny HTML inconsistency (using value=xxx
instead of placing the value in the element text). So I switched to
<input value="{{x.a * x.b}}" tabindex="-1" readonly/>
这解决了这个问题,但不应输入纳克绑定
工作呢?据我所知 jQuery的 VAL()
一样。难道我做错了什么?
which solved the problem, but shouldn't input ng-bind
work anyway? AFAIK jQuery val()
does. Am I doing something wrong?
侧的问题:
- 这是个不好的做法,使用的始终是
只读
? 输入 - 如果是这样,有什么推荐的方法?
跨度
或标签
还是什么?
- Is it a bad practice to use inputs which are always
readonly
? - If so, what's the recommended way?
span
orlabel
or what?
推荐答案
ngBind
设置元素的文本内容:
element.text(value == undefined ? '' : value); // from the source code of Angular
所以,它不设置输入的值工作(也不应该不会吧)
So, it does not work for setting the value of an input (nor shouldn't it).
我相信这是更好地使用&LT;跨度方式&gt;
代替只读输入
I believe it is better to use <span>
in place of readonly inputs.
这篇关于不应该NG-绑定输入工作呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!