One suggestion is to include target="_blank"
in the anchor tag (or button).
<a target="_blank" [routerLink]="['/link'] OR href">
Open in New Window
</a>
Alternatively, have you considered using window.open? It may be a perfect solution for this situation.
Another option is to fetch the file through a service, convert it into a blob, and avoid opening a new window. Would that suit your needs?
public export(): Observable<any> {
return this.http.get(`url/export`, { responseType: 'text' });
}
Then,
public export(): Observable<any> {
return this.apiService.export().pipe(tap(data => downloadAsCSVFile(data, 'test')));
}
const downloadAsCSVFile = (csv: string, fileName: string): void => {
const blob = new Blob([csv], { type: 'text/csv' });
saveAs(blob, `${fileName}.csv`);
};
You could give it a try!