2017-10-09 94 views
0

工作,我试图从成HTML。它下载静态文件不工作静态文件下载没有角4

app.routing.ts

{ path: 'application', component: ApplicationComponent}, 
    // otherwise redirect to home 
    { path: '**', redirectTo: '/home' } 

HTML

<a href="/excel_files/xxx.xlsx" target="_self" class="btn btn-primary"><i class="fa fa-download"></i> Download Spread Sheet</a> 

这里是链接 - http://localhost:4200/excel_files/xxx.xlsx

但它被重定向回家。

谢谢。

+0

你使用angualr.cli – Robert

+0

是的先生。我正在使用角度cli –

回答

1

这里的答案

请将下载属性添加到标签。这将防止溃败的变化,并告诉浏览器它是一个下载链接:

<a href="/excel_files/file_name.xlsx" target="_self" download> 
    <i class="fa fa-download"></i> Download Spread Sheet 
</a> 
+0

感谢您的回复@Robert文件下载成功。但显示xxx.xlsx失败 - 铬 –

+0

没有文件可能是文件路径错误,您可以添加文件夹树 – Robert

+0

angular_project/src/excel_files/file_name.xlsx –