AngularJS - 接收和下载CSV [英] AngularJS - Receive and download CSV

查看:99
本文介绍了AngularJS - 接收和下载CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用nodeJS程序作为服务器和AngularJS Web应用程序作为客户端。

I am using a nodeJS program as a server and an AngularJS web application as the client.

要创建CSV我使用express-csv图书馆( https://www.npmjs.com/package/express-csv

To create the CSV I'm using the "express-csv" library (https://www.npmjs.com/package/express-csv)

这是我的服务器端代码:

Here is my server side code:

定义:

var app = express();
var csv = require('express-csv');

获取代码:

app.get('/exportDB', function(req, res){
    res.csv([
    ["a", "b", "c"]
  , ["d", "e", "f"]
  ]);

这是我的客户端代码:

$http.get("http://"+$localStorage.ip+":"+$localStorage.port+"/exportDB").success(function(response){
            // HERE I NEED A WAY TO DOWNLOAD THE RECEIVED CSV
        });

不用说,它到达服务器,一切都正常工作,但我找不到一个方法来下载CSV。 。

Needless to say it reaches the server and everything else is working just fine, but I couldnt find a way to download the CSV. Help please.

PS

请不要说of 提示一个csv文件,使用node.js和node-csv-parser(节点模块)作为弹出窗口下载,因为客户端没有真正提到。
另外,其他问题集中在服务器端,而不是客户端。

Please don't say it's a duplicate of Prompt a csv file to download as pop up using node.js and node-csv-parser (node module) since the client side isn't really mentioned there. Also, other questions are focused on server side instead of client. There is no other question referring to AngularJS client.

推荐答案

您可以导航:

location.href = "http://"+$localStorage.ip+":"+$localStorage.port+"/exportDB";

这篇关于AngularJS - 接收和下载CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆