Skip to content

Instantly share code, notes, and snippets.

@maykon-oliveira
Last active May 1, 2021 16:08
Show Gist options
  • Save maykon-oliveira/152f0a756b93c00ae1a72d96117ac894 to your computer and use it in GitHub Desktop.
Save maykon-oliveira/152f0a756b93c00ae1a72d96117ac894 to your computer and use it in GitHub Desktop.
Preview de imagens antes do upload com Angular
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