Created
July 17, 2018 21:42
-
-
Save Jerga99/b69eef9899f8a758083a301e3bdfdca6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImageSnippet { | |
constructor(public src: string, public file: File) {} | |
} | |
@Component({ | |
selector: 'bwm-image-upload', | |
templateUrl: 'image-upload.component.html', | |
styleUrls: ['image-upload.component.scss'] | |
}) | |
export class ImageUploadComponent { | |
selectedFile: ImageSnippet; | |
constructor(private imageService: ImageService){} | |
processFile(imageInput: any) { | |
const file: File = imageInput.files[0]; | |
const reader = new FileReader(); | |
reader.addEventListener('load', (event: any) => { | |
this.selectedFile = new ImageSnippet(event.target.result, file); | |
this.selectedFile.pending = true; | |
this.imageService.uploadImage(this.selectedFile.file).subscribe( | |
(res) => { | |
}, | |
(err) => { | |
}) | |
}); | |
reader.readAsDataURL(file); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment