重新加载组件/页面,而不用角度刷新整个页面

问题描述 投票:0回答:1

用户选择要上传的文件后,该文件仅在重新加载整个页面后才可见。我正在寻找一种更简洁的方式来重新加载,以便我可以显示文档。

 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.
   });
 }
javascript angular typescript routes angular2-routing
1个回答
0
投票

您无法重新加载组件,因为组件仅初始化一次。您可以创建一个方法,然后调用该方法并更改组件变量的状态。

© www.soinside.com 2019 - 2024. All rights reserved.