[英]Why ngPattern, ngMinvalue and other validation directives are applicable only for <input>
I discovered that following Angular code doesn't work 我发现遵循Angular代码不起作用
<div ng-model="..." ng-pattern="...">
because Angular has the restriction 因为Angular有限制
var ALIASED_ATTR = {
'ngMinlength': 'minlength',
'ngMaxlength': 'maxlength',
'ngMin': 'min',
'ngMax': 'max',
'ngPattern': 'pattern'
};
function getAliasedAttrName(element, name) {
var nodeName = element.nodeName;
return (nodeName === 'INPUT' || nodeName === 'TEXTAREA') && ALIASED_ATTR[name];
}
The validators will work only with input and textarea but it will be convinied eg for solving the usecase and many others 验证器仅适用于输入和文本区域,但可以说服它,例如用于解决用例等
<div contenteditable ngModel="...">
Why angular has the restriction? 为什么角度有限制?
It was a bug, the issue has been already fixed. 这是一个错误,问题已得到解决。
https://github.com/angular/angular.js/commit/43769fb676ae904852582a2c88a5523f0b9f58fc https://github.com/angular/angular.js/commit/43769fb676ae904852582a2c88a5523f0b9f58fc
https://github.com/angular/angular.js/pull/12658 https://github.com/angular/angular.js/pull/12658
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.