简体   繁体   中英

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.

I've created a custom validation directive called 'wrinteger' which takes two additional attributes (max and min).

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 works since it is not dynamically generated.

newForm is where the problem lies. 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

Min and max are already implemented in angularjs. This should help: 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. 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

I went with the second (unaccepted) answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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