Last active
May 1, 2021 16:08
-
-
Save maykon-oliveira/152f0a756b93c00ae1a72d96117ac894 to your computer and use it in GitHub Desktop.
Preview de imagens antes do upload com Angular
This file contains hidden or 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
function onChange(event: any) { | |
if (!event.target.files[0] || event.target.files[0].length === 0) { | |
alert("Nenhum arquivo selecionado"); | |
return; | |
} | |
const mimeType = event.target.files[0].type; | |
if (mimeType.match(/image\/*/) == null) { | |
alert('Apenas imagens são suportados'); | |
return; | |
} | |
const reader = new FileReader(); | |
reader.readAsDataURL(event.target.files[0]); | |
reader.onload = (_event) => { | |
this.message = ""; | |
this.imageData = reader.result; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment