简体   繁体   English

Angular JSCustom指令验证不适用于动态生成的输入

[英]Angular JSCustom directive validation not working for dynamically generated inputs

I'm using nested ng-forms to validate dynamically generated inputs in angular js, which is only partially working. 我正在使用嵌套的ng-forms来验证angular js中动态生成的输入,这仅部分起作用。

I've created a custom validation directive called 'wrinteger' which takes two additional attributes (max and min). 我创建了一个名为“ wrinteger”的自定义验证指令,该指令具有两个附加属性(最大和最小)。

For some reason, the max and min values aren't getting picked up and causing the max and min error to always be raised. 由于某些原因,最大值和最小值不会被拾取,从而导致始终出现最大值和最小值误差。 I've created a plunker to help explain the situation. 我创建了一个小插曲来帮助解释这种情况。 There are two forms in this plunker, the testForm and newForm. 此插件有两种形式,即testForm和newForm。 testForm works since it is not dynamically generated. testForm有效,因为它不是动态生成的。

newForm is where the problem lies. 问题出在newForm上。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Let me know if I need to make this more clear. 让我知道是否需要更清楚地说明这一点。 Thank you 谢谢

http://plnkr.co/edit/FEkKND4ays4rUrQ898gu?p=preview http://plnkr.co/edit/FEkKND4ays4rUrQ898gu?p=preview

Min and max are already implemented in angularjs. 最小和最大已在angularjs中实现。 This should help: http://docs.angularjs.org/api/ng.directive:input.number 这应该会有所帮助: http : //docs.angularjs.org/api/ng.directive : input.number

Answered my own question. 回答了我自己的问题。

The issue has nothing to do with nested ng-forms or dynamically generated inputs. 此问题与嵌套ng表单或动态生成的输入无关。 I was interpolating the value which needs to be evaluated in the link function of the directive. 我正在对指令的链接函数中需要评估的值进行插值。

Here is the stackoverflow question that's relevant: How to get evaluated attributes inside a custom directive 这是相关的stackoverflow问题: 如何在自定义指令中获取评估的属性

I went with the second (unaccepted) answer. 我回答了第二个(不可接受的)答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM