Last active
May 1, 2021 16:12
-
-
Save maykon-oliveira/e6ac786295b9995cdffdb55308ff74a6 to your computer and use it in GitHub Desktop.
Pipe para fazer o carregamento de um File do sistema de arquivos
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
import { Pipe, PipeTransform } from "@angular/core"; | |
@Pipe({ | |
name: "fileDisplay", | |
pure: true, | |
}) | |
export class FileDisplayPipe implements PipeTransform { | |
transform(value: File): Promise<any> { | |
return new Promise((resolve, reject) => { | |
const reader = new FileReader(); | |
reader.readAsDataURL(value); | |
reader.onload = (_event) => { | |
resolve(reader.result); | |
}; | |
reader.onerror = reject; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment