INPUT TYPE =在angularjs号验证 [英] input type = number validation in angularjs

查看:212
本文介绍了INPUT TYPE =在angularjs号验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证< INPUT TYPE =号> 通过输入[数字]
angularjs模块纳克指令。

I am trying to validate < input type = number > by using input [number] directive of module ng of angularjs.

在使用的类型号的输入,与最大(小),属性设置为数字,如

When using an input of type number, with the max (or min) attribute set to number such as

&LT;输入类型=数字分钟=20最大=40&GT;

它工作得很好,但我在我的最小值和最大值的数据是动态使用纳克重复数据来如

it works fine , but I my min and max data are coming data dynamically using ng-repeat such as

&LT;输入类型=数字分钟=configRow.valueStart最大=configRow.valueEnd&GT;
 那么它不工作。

<input type=number min="configRow.valueStart" max="configRow.valueEnd"> , then it is not working .

我知道,最小值和最大值只接受数字,我不以书面指示该有多好,请大家帮我任何这样的目录或任何建议,将AP preciated。

I know that min and max only accept number and I am not much good in writing directives for that , Please help me any such directory or any suggestions would be appreciated.

推荐答案

最大期待值。所以,这应该工作:

min and max are expecting a value. So, this should work:

<input type=number min="{{configRow.valueStart}}" max="{{configRow.valueEnd}}">

下面是一个 plunker 显示演示。 (这只是一个文档演示的修改)。

Here is a plunker showing a demo. (this is just a modification of the documentation demo).

目前,这些属性的源代码看起来像下面。所以,你可以看到一个预期值,然后将其转换为浮动与 parseFloat 。所以插值模型属性 {{}} 来需要值。

At the moment, the source for these attributes looks like below. So, you can see that a value is expected that is then cast to a float with parseFloat. So interpolating the model property {{}} to a value is required.

的src /纳克/指令/ input.js

if (attr.min) {
        var minValidator = function(value) {
          var min = parseFloat(attr.min);
          return validate(ctrl, 'min', ctrl.$isEmpty(value) || value >= min, value);
        };

        ctrl.$parsers.push(minValidator);
        ctrl.$formatters.push(minValidator);
      }

      if (attr.max) {
        var maxValidator = function(value) {
          var max = parseFloat(attr.max);
          return validate(ctrl, 'max', ctrl.$isEmpty(value) || value <= max, value);
        };

        ctrl.$parsers.push(maxValidator);
        ctrl.$formatters.push(maxValidator);
      }

这篇关于INPUT TYPE =在angularjs号验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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