AngularJS - Receive and download CSV

You can just navigate:

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

I faced same issue that the solutions mentioned above with works well with Chrome and Firefox, but not with safari/IE.

Tried out following hack and it worked for me-

var url="http://'+$localStorage.ip+':"+$localStorage.port+'/exportDB'; var form = angular.element("<form action='" + url +"'></form>"); form.submit();

File download will be handled by browser itself. though following is limitation to it -

  1. You won't be able to handle the errors (if any) from your http get call :( For this tried using try-catch block of javascript, but didn't work well...
  2. ..you wont be able to unit test this piece of code :( :(

There is another approach that worked and it was -

var url="http://'+$localStorage.ip+':"+$localStorage.port+'/exportDB'; $window.location.href = url;

Suggestions and Discussions welcome!