我需要使用多个上传多个图像,但我需要立即显示文件的名称作为标记,我需要将文件移动到数组中。但我只能获取一个文件名。
http://plnkr.co/edit/BSvgdTms8iu2TKekdgtJ?p=preview
JS:
(function (module) {
var fileReader = function ($q, $log) {
var onLoad = function(reader, deferred, scope) {
return function () {
scope.$apply(function () {
deferred.resolve(reader.result);
});
};
};
var onError = function (reader, deferred, 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, deferred, scope);
reader.onerror = onError(reader, deferred, 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
};
};
module.factory("fileReader",
["$q", "$log", fileReader]);
}());
我的代码出现在提供的plunker链接中。我只需要一个图像预览,但下面显示的所有文件名。一旦上传,图像应以数组格式存储。