使用ANGULAR 8从api下载文件
我在后端使用LARAVEL 6.0,在前端使用ANGULAR 8.0.0,我想知道如何将后端生成的文件从前端删除使用ANGULAR 8从api下载文件,angular,laravel,api,Angular,Laravel,Api,我在后端使用LARAVEL 6.0,在前端使用ANGULAR 8.0.0,我想知道如何将后端生成的文件从前端删除 public function exportPdf(Book $book) { $data = ['data' => $book]; $html = view('book.pdf')->with($data)->toHtml(); $mpdf = new \Mpdf\Mpdf(); $mpdf-
public function exportPdf(Book $book)
{
$data = ['data' => $book];
$html = view('book.pdf')->with($data)->toHtml();
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
return response()->download($mpdf->Output('test.pdf', \Mpdf\Output\Destination::DOWNLOAD));
}
提前谢谢我找到了
在app.component.ts上
import {Component, OnInit} from '@angular/core';
import {DomSanitizer} from '@angular/platform-browser';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
name = 'Angular 5';
fileUrl;
constructor(private sanitizer: DomSanitizer) {
}
ngOnInit() {
const data = 'some text';
const blob = new Blob([data], {type: 'application/octet-stream'});
this.fileUrl = this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob));
}
}
app.component.html
<a [href]="fileUrl" download="file.txt">DownloadFile</a>
这里是