不应该NG-绑定输入工作呢? [英] Shouldn't ng-bind work for input as well?

查看:119
本文介绍了不应该NG-绑定输入工作呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点迷惑不解我

<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 or label 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆