asafdav / ng-csv

Simple directive that turns arrays and objects into downloadable CSV files
MIT License
573 stars 215 forks source link

Crashes in chrome. In IE, it shows blank screen.. #47

Closed ArjunKumarDD closed 9 years ago

asafdav commented 10 years ago

Can you please provide an example ?

zhu1230 commented 10 years ago

I also encountered crash(on chrome, firefox is totally ok), but it only happened on some big arrays, like 10000 rows , 5000 rows is fine. Any idea ?

asafdav commented 10 years ago

See #33 I couldn't figure it out so far.

bbarney commented 9 years ago

The Chrome crash is fixed by triggering the download using a object URL created from a blob. In the link function of the directive, set the href attribute like this:

var blob = new Blob([scope.csv],{ type: "text/csv;charset=utf-8;" }); ... downloadLink.attr('href', window.URL.createObjectURL(blob));

Using this method, it is no longer necessary to encode the data, so additional changes were required. Full changes here:

https://github.com/bbarney/ng-csv/commit/49e5cfcf38e550979c4f8bbad2c3e14f11523da4

The current stable version of PhantomJS doesn't support the Blob object yet so I disabled the unit test that was failing. It will pass after upgrading to PhantomJS 2.0.