Skip to content

Instantly share code, notes, and snippets.

@ingeit
Created February 23, 2019 14:51
Show Gist options
  • Save ingeit/b9086e878fbd94926bb5296a8ca9aec4 to your computer and use it in GitHub Desktop.
Save ingeit/b9086e878fbd94926bb5296a8ca9aec4 to your computer and use it in GitHub Desktop.
upload img angular ngzorro zorro image
//HTML
<div>
<nz-upload nzType="drag" [nzBeforeUpload]="beforeUpload" [nzLimit]="1" nzAccept="image/*" nzFIleType="image/*" [nzData]="img"
[nzShowUploadList]="false" [hidden]="disableUpload">
<h2>Subir Flyer</h2>
<p class="ant-upload-drag-icon" *ngIf="!disableUpload">
<i nz-icon type="upload" theme="outline"></i>
</p>
<p class="ant-upload-text" *ngIf="!disableUpload">Click o arrastre la foto a esta zona para subir</p>
</nz-upload>
<div *ngIf="disableUpload">
<div nz-row>
<div nz-col [nzSpan]="22">
<img style="width: 100%;" [src]="flyer" alt="">
</div>
<div nz-col [nzSpan]="2">
<button nz-button nzType="default" nzShape="circle" (click)="deleteFile()" class="delete"><i class="anticon anticon-delete"></i></button>
</div>
</div>
</div>
</div>
// TS
//vars:
flyer: any;
disableUpload: boolean
//function
beforeUpload = (file): boolean => {
var reader = new FileReader();
reader.onloadend = () => {
this.flyer = reader.result;
if(this.flyer) this.disableUpload = true;
console.log('TCL: EventoNuevoComponent -> reader.onloadend -> this.flyer', this.flyer)
}
reader.readAsDataURL(file);
return false;
}
deleteFile() {
this.disableUpload = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment