Add a Slick Angular CSV Download Link 1

misc2Just thought I’d share this bit of code.  It allows an angular client app to create a csv file which can be used in a downloadable link that gets created on the client, on-the-fly, which the browser sees as an attachment:

// Create a downloadable link and click it.
$scope.SubmitFileToUser = function (csvData) {
var element = angular.element(‘<a/>’);
element.attr({
href: ‘data:attachment/csv;charset=utf-8,’ + encodeURI(csvData),
target: ‘_blank’,
download: ‘export.csv’
})[0].click();
};

Update: If this doesn’t work for you, Aydin Akcasu came up with an alternative way to do it here.

One comment

  1. Pingback: Alternate way to Add a Slick Angular CSV Download Link « The Chronicles of Nerdia

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s