Javascript 输入类型=";文件";上载图像文件时显示错误

Javascript 输入类型=";文件";上载图像文件时显示错误,javascript,html,css,angularjs,validation,Javascript,Html,Css,Angularjs,Validation,当我尝试从带有角度验证的文件类型输入上传图像时,它会显示错误并且不会通过 <input type="file" name="displaypic" ng-model="displaypic" ng-pattern="/\.(jpe?g|png|gif|bmp)$/i" ng-required="true" /> <span ng-show="SignupForm.displaypic.$error.pattern">* Must be an Image</span&

当我尝试从带有角度验证的文件类型输入上传图像时,它会显示错误并且不会通过

<input type="file" name="displaypic" ng-model="displaypic" ng-pattern="/\.(jpe?g|png|gif|bmp)$/i" ng-required="true" />
<span ng-show="SignupForm.displaypic.$error.pattern">* Must be an Image</span>  

*一定是图像
以css作为
input.ng无效.ng触摸{边框:2px实心红色;}


它不显示错误
$error.pattern
,但只获取无效文件的css,不允许表单提交

您必须为此使用指令 在控制器中创建对象

$scope.file={};
$scope.file.fileDetail={};

<input type="file" fileUpload filetoread="file.fileDetail" />

.directive("fileUpload ", [function () {
return {
    scope: {
        filetoread: "="
    },
    link: function (scope, element, attributes) {
        element.bind("change", function (changeEvent) {
            var reader = new FileReader();
            reader.onload = function (loadEvent) {
                scope.$apply(function () {
                    scope.filetoread= loadEvent.target.result;
                });
            }
            reader.readAsDataURL(changeEvent.target.files[0]);
        });
    }
}
 }]);
$scope.file={};
$scope.file.fileDetail={};
.directive(“fileUpload”,[函数(){
返回{
范围:{
filetoread:“”
},
链接:功能(范围、元素、属性){
元素绑定(“更改”,函数(changeEvent){
var reader=new FileReader();
reader.onload=函数(loadEvent){
作用域:$apply(函数(){
scope.filetoread=loadEvent.target.result;
});
}
reader.readAsDataURL(changevent.target.files[0]);
});
}
}
}]);

您必须为此使用指令 在控制器中创建对象

$scope.file={};
$scope.file.fileDetail={};

<input type="file" fileUpload filetoread="file.fileDetail" />

.directive("fileUpload ", [function () {
return {
    scope: {
        filetoread: "="
    },
    link: function (scope, element, attributes) {
        element.bind("change", function (changeEvent) {
            var reader = new FileReader();
            reader.onload = function (loadEvent) {
                scope.$apply(function () {
                    scope.filetoread= loadEvent.target.result;
                });
            }
            reader.readAsDataURL(changeEvent.target.files[0]);
        });
    }
}
 }]);
$scope.file={};
$scope.file.fileDetail={};
.directive(“fileUpload”,[函数(){
返回{
范围:{
filetoread:“”
},
链接:功能(范围、元素、属性){
元素绑定(“更改”,函数(changeEvent){
var reader=new FileReader();
reader.onload=函数(loadEvent){
作用域:$apply(函数(){
scope.filetoread=loadEvent.target.result;
});
}
reader.readAsDataURL(changevent.target.files[0]);
});
}
}
}]);

input[type=file]
没有。我现在应该做什么?您可以尝试使用中提到的
指令
或中的其他一些指令。
input[type=file]
没有。我现在应该做什么?您可以尝试使用中提到的
指令或中的其他一些指令。