我想在图片上传时针对最大尺寸和无效格式显示不同的验证消息。 这是我的代码,但最大大小验证不起作用,仅显示无效的文件格式验证。
这是我的代码。
<div class="group-row col-sm-10 col-sm-push-1">
<input class="control-set" type="file" ngf-select ng-model="image" name="image" ngf-pattern="'image/*'" ngf-accept="'image/*'" ngf-max-size="5MB" ngf-multiple="false" ngf-min-size='1' ui-jq="filestyle">
<div ng-show="createUserForm.$submitted || createUserForm.image.$invalid" ng-model="image">
<span ng-show="createUserForm.image.maxSize" class="text-danger">File must be less than 5 MB.</span>
<span ng-show="createUserForm.image.$invalid" class="text-danger">Only .jpg,jpeg and .png images are allowed.</span>
</div>
</div>
我在这里犯了什么错误???
最佳答案
使用 createUserForm.image.$error.maxSize 显示错误 缺少 $error
<span ng-show="createUserForm.image.$error.maxSize" class="text-danger">File must be less than 5 MB.</span>
关于angularjs - Angular JS 图像验证最大尺寸和有效格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38822477/