2016-04-26 52 views
0

我有這樣的代碼在laravel出口擅長:如何從Laravel 5.1獲得下載文件,AngularJS和UI路由器

public function export_excel(Request $request){  
    $user = user::all(); 
    Excel::create('user', function($excel) use($user) { 
     $excel->sheet('Sheet 1', function($sheet) use($user) { 
      $sheet->fromArray($user); 
     }); 
    })->download('xls'); 
} 

,我的路線是:

Route::get('user/export/excel','[email protected]_excel'); 

和我的HTML是:

<a><i class="fa fa-file-excel-o"></i> Export to Excel</a> 

我想給從REST API請求與Restangular並獲得下載文件之後。

回答

2

我解決了問題,這樣的:

this.downloadExcel = function(){ 
     Restangular.one('user/export/excel').withHttpConfig({responseType: 'blob'}).get().then(function(response) { 
      var url = (window.URL || window.webkitURL).createObjectURL(response); 
      window.open(url,"_self"); 
     }) 
    } 
-1

你可以簡單的使用href屬性

<a href="user/export/excel" target="_BLANK"> 
    <i class="fa fa-file-excel-o"></i> Export to Excel 
</a> 
+0

在SPA的應用程序直接指向API是不是一個好的做法! – Fara