Skip to content

Instantly share code, notes, and snippets.

@umutyerebakmaz
Last active May 8, 2020 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umutyerebakmaz/ecde44064c9d556acc6b87cfdfaa9449 to your computer and use it in GitHub Desktop.
Save umutyerebakmaz/ecde44064c9d556acc6b87cfdfaa9449 to your computer and use it in GitHub Desktop.
onFileChanged(event: any) {
// dosyayı seç
this.selectedFile = event.target.files[0];
// seçili resim yoksa dur!.
if (!this.selectedFile) {
return;
}
// seçilen resmin önizlemesini göstermek için
const fileReader = new FileReader();
fileReader.readAsDataURL(this.selectedFile);
fileReader.onload = (_event: any) => {
this.fileURL = fileReader.result;
};
this.makeNewFileName();
}
removeFile(event: any) {
// dosyayı seç
this.selectedFile = null;
this.fileURL = null;
this.newFileName = null;
console.log(this.selectedFile, this.fileURL, this.newFileName);
}
<div class="full-width" fxLayout="column" fxLayoutAlign="space-between center">
<div>
<img [src]="fileURL" height="100" *ngIf="fileURL">
</div>
<div>
<input #file type="file" name="file" title="file" accept='image/*' (change)="onFileChanged($event)"
style="display: none">
<button mat-button (click)="file.click()">RESİM EKLE</button>
<button mat-button (click)="removeFile()" *ngIf="fileURL">RESMİ KALDIR</button>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment