简体   繁体   English

角度验证:如果动态添加所需的属性,验证将失败

[英]Angular validation: if dynamically add required attribute validation will break

Trying to dynamically add validation to input file if I choose first option from select. 如果我从select中选择第一个选项,则尝试向输入文件动态添加验证。 But if I add required attribute, it still ng-valid in class. 但是,如果我添加了required属性,则它在类中仍为ng-valid If I load file to input file, it still ng-empty . 如果我将文件加载到输入文件,则仍为ng-empty What's wrong? 怎么了? http://plnkr.co/edit/pjyCULes60jWf7yqNsyB?p=preview http://plnkr.co/edit/pjyCULes60jWf7yqNsyB?p=preview

The form validation in AngularJS depends on the ngModel attribute, which doesn't work with input type=file . AngularJS中的表单验证取决于ngModel属性,该属性不适用于input type=file

To solve this, either use ngFileUpload which helps you solve other problems you'll encounter with file upload in Angular as well, or see this or that answer. 要解决此问题,请使用ngFileUpload(它可以帮助您解决在Angular中上传文件时也会遇到的其他问题),或者查看答案。

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

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