title: Parsing moment() object as filename with ngCsv and AngularJS
body: <p>I'm trying to properly format an object to be inserted as a filename in ngCsv.</p>
  
  <p>ngCsv uses the <code>filename="name.csv"</code> attribute, but I need to use an object with two properties as filename. The object comes from <code>ng-model="dates"</code>, has two momentJS properties and looks like this:</p>
  
  <p>{-startDate---2014-11-05T21-00-00.000Z-,-endDate---2014-11-05T21-00-00.000Z-}</p>
  
  <p>I've tried to use <code>{{dates}}</code> as filename like follows:</p>
  
  <pre><code>&lt;button ng-csv="filteredRecords" 
          filename="{{dates}}.csv"&gt;Download results as CSV
  &lt;/button&gt;
  </code></pre>
  
  <p>But then the resulting file is obviously called <code>{-startDate---2014-11-05T21-00-00.000Z-,-endDate---2014-11-05T21-00-00.000Z-}.csv</code> because the dates have no format. </p>
  
  <p>The desired result would be something like <code>23-12-2014 - 25-12-2014.csv</code>.</p>
  
  <p>I've also tried to format them before in the attribute like so:</p>
  
  <pre><code>&lt;button ng-csv="filteredRecords" 
          filename="{{ moment(dates.startDate, 'DD[/]MM[/]YYYY') - moment(dates.endDate, 'DD[/]MM[/]YYYY')}}.csv""&gt;
              Download results as CSV
  &lt;/button&gt;
  </code></pre>
  
  <p>But that doesn't work either. Any idea on how to accomplish this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The solution from Davin works perfectly.</p>
  
  <p>I've tried to make it work further by including also in the filename other fields from the filter.</p>
  
  <pre><code>&lt;div class="form-group col-md-1"&gt;
     &lt;input class="form-control" placeholder="Car" ng-model="search.car"&gt;
  &lt;/div&gt;
  &lt;div class="form-group col-md-2"&gt;
     &lt;input class="form-control" placeholder="Driver" ng-model="search.driver"&gt;
  &lt;/div&gt;
  
  &lt;button class="btn btn-success" 
          type="button" 
          ng-csv="filteredRecords" 
          filename="{{ createCsvFilename(dates, search) }}"&gt;
             Download
  &lt;/button&gt;
  </code></pre>
  
  <p>And the JS: </p>
  
  <pre><code>$scope.createCsvFilename = function(dates, search) {
      var startMoment = moment(dates.startDate);
      var endMoment = moment(dates.endDate);
      var filterCar = search.car;
      var filterDriver = search.driver;
      return startMoment.format('DD-MM-YYYY') + ' - ' + 
             endMoment.format('DD-MM-YYYY') + 
             ' - Car_' + filterCar  + ' - Driver_' + filterDriver + '.csv';
  }
  </code></pre>
  
  <p>It also works, and I get the desired filename, but I get some errors in the console, because before applying any filter (date range or otherwise), both <code>startDate</code>, <code>endDate</code> and <code>search</code> are undefined. </p>
  
  <p>Any workaround for this? Is just to leave it as neat as possible, because as I already said, it delivers the expected results.</p>