在我开始使用Angular 17版本并推荐使用with Fetch之后,搜索BLOB的GET方法停止工作. 如果您不使用WITH Fetch,PDF将在我的模板的IFRAME内正常打开. 注意:编译期间或运行时不会显示任何错误.PDF显示有错误的内容,显示奇怪的文本和字符. 下面的代码中有什么错误?会不会是个窃听器?
App.config.ts
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideHttpClient(
withInterceptorsFromDi(),
withFetch()
),
...
}
Services.ts
public downloadDiagrammedPdf(sumarioId: number, nomeDoDiagramaPDF: string): Observable<HttpEvent<Blob>> {
return this.http.request(
new HttpRequest('GET', `${this.apiDownloadPdfUrl}?sumarioId=${sumarioId}&nomeDoDiagramaPDF=${nomeDoDiagramaPDF}`, null, {
reportProgress: true,
responseType: 'blob',
})
);
}
ShowPdf.componente.ts
downloadFile(sumarioId: number, nomeDoDiagramaPDF: string): void {
this.serviceUpDown.downloadDiagrammedPdf(sumarioId, nomeDoDiagramaPDF).subscribe({
next: (data) => {
switch (data.type) {
case HttpEventType.DownloadProgress:
break;
case HttpEventType.Response:
//this.downloadStatus.emit({ status: ProgressStatusEnum.COMPLETE });
const file = new Blob([data.body as BlobPart], {
type: data.body?.type,
});
this.createPdfFromBlob(file);
break;
}
},
error: (err) => {
//this.downloadStatus.emit({ status: ProgressStatusEnum.ERROR });
if (err.status == 404) {
this.router.navigate(['app-error-page']);
}
else
console.log(err);
},
complete: () => { }
});
}
createPdfFromBlob(file: Blob) {
this.pdfSrc = this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(file));
}
版本:
{
"@angular/animations": "^17.0.2",
"@angular/cdk": "^17.0.0",
"@angular/common": "^17.0.2",
"@angular/compiler": "^17.0.2",
"@angular/core": "^17.0.2",
"@angular/forms": "^17.0.2",
"@angular/material": "^17.0.0",
"@angular/platform-browser": "^17.0.2",
"@angular/platform-browser-dynamic": "^17.0.2",
"@angular/platform-server": "^17.0.2",
"@angular/router": "^17.0.2",
"@angular/ssr": "^17.0.0",
"@auth0/angular-jwt": "^5.1.2",
"@material/icon-button": "^15.0.0-canary.684e33d25.0",
"angular-imask": "^7.1.3",
"express": "^4.15.2",
"ngx-toastr": "^17.0.2",
"rxjs": "~7.8.1",
"tslib": "^2.6.2",
"zone.js": "~0.14.2"
}