为什么角提供NG-最大长度时,有一个标准的最大长度? [英] Why does Angular provide ng-maxlength when there is a standard maxlength?

查看:127
本文介绍了为什么角提供NG-最大长度时,有一个标准的最大长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

4.01版本标准maxlength属性。
角提供 NG-最大长度指令。

HTML provides a standard maxlength attribute since version 4.01. Angular provides a ng-maxlength directive.

不同的是,该标准方法不允许进入比最大值以上,而角的做法只是产生一个验证错误。

The difference is that the standard approach doesn't allow entering more than max, while Angular's approach just generates a validation error.

为什么他们决定包括这样的指令?这是因为动态数据最大长度的结合,因为行为是不一致的不是。这不是因为兼容性,因为它即使在HTML 4.01可用。我唯一​​的猜测是,它的存在提供一种替代的验证模式,但它听起来像是过度工程。

Why did they decide to include such a directive? It's not because of dynamic data binding of maxlength since the behaviour is inconsistent. It's not because of compatibility since it's available even in HTML 4.01. My only guess is that it's there to provide an alternative validation paradigm, but it sounds like over-engineering.

推荐答案

它不仅提供了最大长度的验证,还增加了一类 NG-无效,最大长度
所以当你把任何东西超越极限 NG-无效,最大长度类将放在那里
并且在类中,你可以写自己的CSS。

Not only it provide validation for max length, it also adds a class ng-invalid-maxlength. so when you put anything beyond the limit ng-invalid-maxlength class will placed there and in that class you can write your own css.

所以经过键preSS如果验证失败,CSS将同时调用,并且在你的UI体现。

So after key press if validation fails, the css will be invoked simultaneously and reflects on your UI.

这篇关于为什么角提供NG-最大长度时,有一个标准的最大长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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