Skip to content

Instantly share code, notes, and snippets.

@paulomenezes
Created August 21, 2017 15:36
Show Gist options
  • Select an option

  • Save paulomenezes/f7b8429fcc11ef726a6de29d9a8afcce to your computer and use it in GitHub Desktop.

Select an option

Save paulomenezes/f7b8429fcc11ef726a6de29d9a8afcce to your computer and use it in GitHub Desktop.
File Upload
<input #uploadButton type="file" (change)="fileChangeEvent($event)" class="hidden" />
<button type="button" class="btn btn-primary" (click)="fileUpload()">Escolher Foto</button>
@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