Created
August 21, 2017 15:36
-
-
Save paulomenezes/f7b8429fcc11ef726a6de29d9a8afcce to your computer and use it in GitHub Desktop.
File Upload
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
| <input #uploadButton type="file" (change)="fileChangeEvent($event)" class="hidden" /> | |
| <button type="button" class="btn btn-primary" (click)="fileUpload()">Escolher Foto</button> |
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
| @ViewChild('uploadButton') fileInput: any; | |
| fileUpload() { | |
| this.fileInput.nativeElement.click(); | |
| } | |
| // When choose the file | |
| fileChangeEvent(fileInput: any) { | |
| const reader = new FileReader(); | |
| this.url = ''; | |
| reader.onload = (event: any) => { | |
| this.url = event.target.result; | |
| this.userModel.photo = event.target.result; | |
| }; | |
| reader.readAsDataURL(fileInput.target.files[0]); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment