title: Download text/csv content as files from server in Angular
body: <p>I am trying to stream a <code>csv</code> file from a node.js server. The server portion is very simple :</p>
  
  <pre><code>server.get('/orders' function(req, res) {
    res.setHeader('content-type', 'text/csv');
    res.setHeader('content-disposition', 'attachment; filename='orders.csv');
    return orders.pipe(res); // assuming orders is a csv file readable stream (doesn't have to be a stream, can be a normal response)
  }
  </code></pre>
  
  <p>In my angular controller I am trying to do something like this </p>
  
  <pre><code>$scope.csv = function() {
      $http({method: 'GET', url: '/orders'});
  };
  </code></pre>
  
  <p>This function is called when there's a click on a button with <code>ng-click</code> in my view :</p>
  
  <pre><code>&lt;button ng-click="csv()"&gt;.csv&lt;/button&gt;
  </code></pre>
  
  <p>I have looked at other answers about downloading files from server in Angular, but didn't find anything that worked for me. Is there a common way to do this ? Seems like something that should be simple.</p>