Last active
May 8, 2020 14:14
-
-
Save umutyerebakmaz/ecde44064c9d556acc6b87cfdfaa9449 to your computer and use it in GitHub Desktop.
This file contains 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
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); | |
} |
This file contains 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
<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