AngularJS:无法更改输入类型 [英] AngularJS: can't change input type

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

问题描述

每当我有一个 Angular 表达式作为 inputtype 的值时,它就不起作用:

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 需要跨浏览器兼容.因此,即使您可能看到源代码中显示的已更改类型,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

动态类型的唯一选项是自定义指令(您可以在其中下载动态模板或即时准备 DOM)或使用 ng-include 在输入的位置包含部分type 是一个静态值.

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天全站免登陆