gpt4 book ai didi

javascript - ngf-max-size $digest() 与 angular.js 中的 ng-file-upload 错误

转载 作者:行者123 更新时间:2023-12-03 05:25:34 25 4
gpt4 key购买 nike

这是源代码。

<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() 错误始终出现在下面。

enter image description here

我还有一个问题。在找到解决此问题的解决方案后,当有人上传超过 max_size 的图像时,我会发出警报消息。

谢谢您的回答。

最佳答案

您不应该更改 watch 内的模型,因为它会创建循环。如果您只需要在文件上传时提醒是否超出大小,您只需检查状态即可。

假设您有以下输入:

 <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>

而且您也不需要指令来处理该问题。

检查here有关验证的更多信息。

关于javascript - ngf-max-size $digest() 与 angular.js 中的 ng-file-upload 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41155650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com