It depends on what you mean to see the files...
But basically, you should save the dragged files to a class attribute and display it in your html:
app.component.ts
import { Component, OnInit, HostListener } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
error: string;
dragAreaClass: string;
draggedFiles: any;
...
saveFiles(files: FileList) {
if (files.length > 1) this.error = "Only one file at time allow";
else {
this.error = "";
console.log(files[0].size,files[0].name,files[0].type);
this.draggedFiles = files;
console.log(files);
}
}
}
app.component.html
<div draggable="true" ngClass="{{dragAreaClass}}">
<div class="row">
<div class="col-md-12 text-center">
Drag files here
<a href="javascript:void(0)" (click)="file.click()">
or click to open
</a>
<input type="file"
#file
[multiple]="false"
(change)="onFileChange($event)"
style="display:none" />
<div class="dragged-files-wrapper" *ngIf="draggedFiles">
<div class="file" *ngFor="let file of draggedFiles">
{{file}}
</div>
</div>
</div>
</div>
</div>
<div class="error" *ngIf="error">
Only one file at time allow
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…