AngularJS:不能改变输入类型 [英] AngularJS: can't change input type

查看:115
本文介绍了AngularJS:不能改变输入类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Whenver我有一个角前pression作为值输入的 键入,它赢得'T的工作:

Whenver I have an Angular expression as a value to input's type, it won't work:

<input ng-model="model" type="{{'number'}}">

数字值被转换为字符串和复选框将无法工作。

Numeric values get converted to strings and checkboxes won't work at all.

http://jsfiddle.net/punund/NRRj7/3/

推荐答案

您不能动态地改变输入的类型,因为IE不允许这一点,AngularJS必须是跨浏览器兼容。所以,即使你可能会看到改变的类型在源$ C ​​$ C AngularJS显示不会把它捡起来 - 类型只计算一次,不能更改

You can't change input's type dynamically since IE disallows this and AngularJS needs to be cross-browser compatible. So even if you might see the changed type displayed in the source code AngularJS won't pick it up - type is only evaluated once and can't be changed.

请注意,同样的限制适用于jQuery的: jQuery的改变输入类型

Please note that the same restriction applies to jQuery: jQuery change input type

您只对动态类型的选项要么自定义指令(在这里你可以下载一个动态模板或prepare上即时DOM)或使用 NG-包括包括包括谐音,其中输入类型是一个静态值。

You only options for dynamic types are either a custom directive (where you can download a dynamic template or prepare DOM on-the-fly) or using ng-include to include include partials where the input type is a static value.

这篇关于AngularJS:不能改变输入类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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