This is for angular type script:
1.app.cpmponent.html
<div class="wapper">
<button (click)="toggle()"></button>
<div class="up" *ngIf="show">
<label>
<input type="file" (change)="handleFileImage($event.target.files)" accept=".jpg,.svg,.png,.jpeg " />
<img width="100%" height="100%" *ngIf="imageUrl" [src]="imageUrl" class="image" />
</label>
</div>
<div class="up" *ngIf="!(show)">
<label>
<input type="file" (change)="handleFileVideo($event.target.files)" accept=".mp4" />
<video autoplay width="100%" height="100%" *ngIf="videoUrl" class="image">
<source [src]="videoUrl" autoplay>
</video>
</label>
</div>
</div>
2.app.component.ts
export class AppComponent{
fileToUpload: any;
imageUrl: any;
videoUrl: any;
show = true;
handleFileImage(file: FileList) {
this.fileToUpload = file.item(0);
//Show image preview
let reader = new FileReader();
reader.onload = (event: any) => {
this.imageUrl = event.target.result;
};
reader.readAsDataURL(this.fileToUpload);
}
handleFileVideo(file: FileList) {
this.fileToUpload = file.item(0);
let reader = new FileReader();
reader.onload = (event: any) => {
this.videoUrl = event.target.result;
};
reader.readAsDataURL(this.fileToUpload);
}
toggle() {
this.show = !this.show;
if (this.show) {
} else {
}
}
}