I am getting one html page as response from an API call. I want to show it to the frontend side. What would be the best possible way I can do?
I have used httpClient
request to get the data and iframe
to show it and it works fine with me,but I want to show the data in whole new HTML page.
@ViewChild("iframe", { static: true }) iframe: ElementRef;
//getting the iframe references from the html
//From service
getDataSummary() {
return this._http.get(this.dataSummaryUrl, { responseType: "text" });
}
//Component ts file code
onClickDataSummary() {
this.fileUploadService.getDataSummary().subscribe(
data => {
let doc =
this.iframe.nativeElement.contentDocument ||
this.iframe.nativeElement.contentWindow;
doc.open();
doc.write(data);
doc.close();
this.dataSummaryLoading = false;
this.dataSummaryDiv = true;
this.showLoader = false;
},
error => {
alert(` ${error.statusText} occurred!! Please check server side`);
this.dataSummaryLoading = false;
this.dataSummaryDiv = true;
this.showLoader = false;
}
);
}
}
The HTML code would be like this -
<mat-tab label="Data Summary">
<mat-toolbar color="">
<span>Data Summary</span>
<span class="example-fill-remaining-space"></span>
<span
><button
mat-raised-button
class=" mb-2"
color="primary"
(click)="onClickDataSummary()"
*ngIf="!dataSummaryLoading"
>
Data Summary
</button></span
>
<button
class=" mb-2"
mat-raised-button
color="primary"
*ngIf="dataSummaryLoading"
>
<span class="spinner-border spinner-border-sm "></span>
Loading
</button>
</mat-toolbar>
<div
class="example-container mat-elevation-z8"
[class.hide]="!dataSummaryDiv"
>
<iframe width="100%" height="100%" #iframe></iframe>
</div>
<div class="text-center m-5" [class.hide]="!showLoader">
<app-loader></app-loader>
</div>
</mat-tab>
Expected output would be to get the html page when click on a button. like here on clicking of Data Summary
not in iFrame
.
Thanks is advance for your time here.