My view has some simple code:
HERE{{ files.length }}THERE
<div class="uploaded-files" *ngIf="files.length > 0">
<div class="uploaded-files-title">
<h4>Selected Files</h4><h5> (X)</h5>
</div>
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">File Name</th>
<th scope="col">File Size</th>
<th scope="col" class="text-center">Upload Status</th>
<th scope="col" class="text-center"><a href="" (click)="removeAll($event)">Remove All</a></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let file of files">
<td>{{ file.relativePath }}</td>
<td>{{file.size}}</td>
<td class="text-center"><i class="mdi mdi-check-circle mdi-24px approved"></i></td>
<td class="text-center"><i class="mdi mdi-delete mdi-24px actions"></i></td>
</tr>
My component is:
import {
Component,
OnInit
} from '@angular/core';
import { UploadEvent, UploadFile, FileSystemFileEntry } from 'ngx-file-drop';
@Component({
selector: 'upload-modal', // <upload-modal></upload-modal>
providers: [
],
styleUrls: [ './upload.component.scss' ],
templateUrl: './upload.component.html'
})
export class UploadComponent implements OnInit {
constructor() {
}
public files: UploadFile[] = [];
public ngOnInit() {
}
dropFile(event) {
let droppedFiles: UploadFile[] = []
if(this.files.length === 1) {
return
}
const fileEntry = event.files[0].fileEntry as FileSystemFileEntry;
fileEntry.file(fileData => {
console.log('before', this.files)
this.files.push({
name: fileEntry.name,
size: fileData.size
})
console.log('after', this.files)
})
}
handleFileInput() {
alert('files')
}
removeAll(event) {
event.stopPropagation()
this.files: UploadFile[] = []
}
}
When my component's dropFile
function does what it does, the console
prints out correctly, but the view doesn't have any updated files.
I'm using angular 5.2.0
. What am I doing wrong?