![](/img/trans.png)
[英]ng-file-upload validation (ngf-[max|min]-[height|width] or ngf-dimensions) not appearing to take effect
[英]ngf-max-size $digest() error with ng-file-upload in angular.js
這是源代碼。
<div class="thumbnail" ngf-accept="'image/*'" ngf-pattern="'*.jpg,*.jpeg,*.gif,*.png'" ngf-max-size="1MB">
矯正性HTML模板下方。
angular.module('ptgui.imagebox',[
'ngFileUpload'
])
.directive('ptguiImagebox', ['$compile', function($compile) {
return {
templateUrl: 'scripts/libs/ptgui/ptgui-imagebox.html',
restrict: 'E',
require: 'ngModel',
scope: {
ngModel: "="
},
replace: true,
link: function ($scope, element, attrs) {
$scope.$watch('ngModel',function(newFile, oldFile){
if (newFile) {
$scope['ngModel'] = newFile;
} else {
$scope['ngModel'] = oldFile;
}
});
}
};
}]);
在指令下方。
當我通過max_size上傳圖片時,以下始終出現$ digest()錯誤。
我還有一個問題。 找到解決此問題的解決方案后,當有人上傳超過max_size的圖像時,我會發出警報消息。
謝謝你的回答。
您不應該在手表內部更改模型,因為它會創建一個循環。 如果您只需要在文件上傳時提醒大小是否超過該大小,就可以檢查狀態。
假設您輸入以下內容:
<input type="file" ngf-select ng-model="picFile" name="file"
accept="image/*" ngf-max-size="1MB" required
ngf-model-invalid="errorFile">
然后,您只需要在html中顯示它,即可顯示超出限制大小的警報:
<i ng-show="myForm.file.$error.maxSize">File too large
{{errorFile.size / 1000000|number:1}}MB: max 1M</i>
而且您也不需要指令來處理。
在此處查看有關驗證的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.