用户选择要上传的文件后,该文件仅在重新加载整个页面后才可见。我正在寻找一种更简洁的方式来重新加载,以便我可以显示文档。
public onFileSelected(event): void {
console.log(this.fileId)
const file = event.target.files[0];
if (file) {
const formData = new FormData();
formData.append("file", file, file.name);
this.testService.postUrl(`${this.fileId}/upload-document`, formData)
.subscribe((data) => {
Swal.fire("Document", "The document has been uploaded.", "success");
});
}
this.getDocuments();
//this.router.routeReuseStrategy.shouldReuseRoute = () => false;
const RedirectUrl ='/portal/docupload/' + this.fileId
this.router.navigateByUrl('/portal/docupload/' + this.fileId, {skipLocationChange: true}).then(() => {
this.router.navigate([RedirectUrl]);
this.active = 4;
// When skipLocationChange true, navigates without pushing a new state into history.
});
}
您无法重新加载组件,因为组件仅初始化一次。您可以创建一个方法,然后调用该方法并更改组件变量的状态。