rush:js;">
cope) {
return function () {
scope.$apply(function () {
deferred.resolve(reader.result);
});
};
};
var onError = function (reader,scope) {
return function () {
scope.$apply(function () {
deferred.reject(reader.result);
});
};
};
var onProgress = function(reader,scope) {
return function (event) {
scope.$broadcast("fileProgress",{
total: event.total,loaded: event.loaded
});
};
};
var getReader = function(deferred,scope) {
var reader = new FileReader();
reader.onload = onLoad(reader,scope);
reader.onerror = onError(reader,scope);
reader.onprogress = onProgress(reader,scope);
return reader;
};
var readAsDataURL = function (file,scope) {
var deferred = $q.defer();
var reader = getReader(deferred,scope);
reader.readAsDataURL(file);
return deferred.promise;
};
return {
readAsDataUrl: readAsDataURL
};
});
5242880){//单位是B,此处不允许超过5M
alert("图片不能超过5M")
return;
}
if(fileType=='JPG' || fileType=='PNG' || fileType=='JPEG ' || fileType=='jpg' || fileType=='png' || fileType=='jpeg'){
}else{
alert("图片格式只支持:JPG,PNG,JPEG")
return;
}
fileReader.readAsDataUrl(fileIn,$scope)
.then(function(result) {
$scope.imageSrc = result;
console.log(img.width);
});
}
总结
以上所述是小编给大家介绍的Angularjs实现上传图片预览功能。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持。