档案下载XLS-Angular 2-无法正常运作

时间:2018-11-19 14:23:53

标签: angular rest api

这是我的情况:

Service.ts

excelGeneration(filters) {
        var timestamp = new Date().getTime();
      /*  var options = this.setOptions();*/
        let headers = new Headers();
        headers.append('Accept', 'application/vnd.ms-excel');
        let options = new RequestOptions({ headers: headers, body: "", responseType: ResponseContentType.Blob });
        return this.http.post(AppSettings.BASEURL_LOCAL + 'esportacatalogo', filters, options).map(res => new Blob([res.blob()],{ type: 'application/vnd.ms-excel' }))
            .catch((error: any) => {
                this.handleError(error);
                return observableThrowError(error.statusText);
            }).finally(() => {
                this.hideLoader();
            });

    }

Component.ts

generaExcel(){
    let self = this;
    let filters = {};
     self.pageService.excelGeneration(filters).toPromise().then(response => {
       const url= window.URL.createObjectURL(response);
        window.open(url);
    });
  }

我期望Back End能够提供类似“ Hello World”之类的消息。 Atm我正在下载带有此消息“响应状态代码200 OK”的Excel。

我错了哪里?谢谢

0 个答案:

没有答案