Как я могу отобразить html отчет (сгенерированный с помощью jasper) в угловом компоненте? - PullRequest
0 голосов
/ 18 ноября 2018

В home.component.html

Для отображения отчета в угловом домашнем компоненте.

<div *ngIf="showHtml">Report has been rendered!
<div [innerHtml]="htmlReport">
</div>
</div>

В home.component.ts

получение ответа в виде html, исоздание его временного тега привязки для загрузки сгенерированного отчета html.

export class HomeComponent implements OnInit {
showHtml: boolean = false;
onGenerateReportUsingSp2() {
this.state = this.formControl.State.value;
this.city = this.formControl.City.value;
this.reportType = 'html';
this.reportService.generatePdfReportUsingSpcall2(this.state, this.city, this.reportType).subscribe(
  response => {
    const htmlReport = new Blob([response.body], {type: 'text/html'});
    this.htmlReportUrl = window.URL.createObjectURL(htmlReport);
    const anchor = document.createElement('a');
    anchor.download = response.headers.get('file-name');
    anchor.href = this.htmlReportUrl;
    anchor.click();
    this.htmlReport = response.body.toString();
    this.showHtml = true;
  });

In service.ts

Получение типа ответа в виде текста / html в сервисе.

generatePdfReportUsingSpcall2(state: string, city: string, reportType: 
     string): Observable<any> {

 return this.httpClient.post<any>(this.url + 'generateReportInSpCall2', { state, city, reportType }, {observe: 'response', responseType  : 'blob' as 'json'});

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...