.service('SPUD', function() {
let make = function(selectorId, imageId, dataObject, scope) {
let selector = document.getElementById(selectorId);
let image;
if (imageId) {
image = document.getElementById(imageId);
}
let select = function() {
let reader = new FileReader();
reader.onload = function(event) {
let dataURL = reader.result;
if (image) {
image.src = dataURL;
}
dataObject.data = dataURL;
scope.$apply();
};
dataObject.fileName = selector.value.split(/(\\|\/)/g).pop();
let file = selector.files[0];
reader.readAsDataURL(file);
};
let discard = function() {
selector.value = '';
if (image) {
image.src = '';
}
dataObject.data = undefined;
dataObject.fileName = undefined;
};
return {
select: select,
discard: discard,
};
};
return {
make: make,
};
});
-
Notifications
You must be signed in to change notification settings - Fork 0
GoodUncleFood/spud
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Angular 1.x and HTML5 code snippets to select, upload, preview, and delete images and other media.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published