1. 程式人生 > >Angular5 UI post 請求 輸出 檔案下載

Angular5 UI post 請求 輸出 檔案下載

  this.httpClient.post(url1, JSON.parse(data1) , {responseType: 'blob'}).subscribe(data => {
            const link = document.createElement('a');
            const blob = new Blob([data], {type: 'application/vnd.ms-excel'});
            link.setAttribute('href', window.URL.createObjectURL(blob));
            link.setAttribute(
'download', 'Inventory' + new Date().getTime() + '.xls'); link.style.visibility = 'hidden'; document.body.appendChild(link); link.click(); document.body.removeChild(link); }); }
View Code