使用Angular.js在输入类型文件中获取验证错误

时间:2016-02-23 06:05:09

标签: javascript angularjs ng-file-upload

使用Angular.js选择文件时遇到问题。这是我的代码:

<div ng-class="{'myError': billdata.compregdoc.$touched && billdata.compregdoc.$invalid }">
  <input type="file" 
         class="filestyle form-control" 
         data-size="lg" 
         name="compregdoc" 
         id="compregdoc" 
         ng-model="compregfile" 
         ngf-pattern="application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
         accept="application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.wordprocessingml.document" 
         ngf-select="onCompRegFileSelect($file);" 
         ngf-max-size="2MB">

  <div style="clear:both;"></div>
</div>
</div>
<div class="help-block" 
     ng-messages="billdata.compregdoc.$error" 
     ng-if="billdata.compregdoc.$touched">

  <p ng-message="pattern" style="color:#F00;">This field only accepts .pdf,.ppt,.docx files.</p>
  <p ng-message="maxSize" style="color:#F00;">File is too large.Max size is 2 mb.</p>
</div>

在这种情况下,我只能上传pdf类型文件。但在这里我需要pdf,ppt,docx,excel格式文件上传。当我选择docx文件时,它会向我显示This field only accepts .pdf,.ppt,.docx files

的验证消息

0 个答案:

没有答案