title: Download file button with JS
body: <p>I need to generate the link and then download the link in one move. I have a button for generation and download and once is clicked i have to call the api to generate the download link for the pdf and then make the browser open the pop up with save item.</p>
  
  <pre><code>            &lt;button type="button" class="btn btn-success btn-block" ng-click="generateAndDownloadPdf()"&gt;&lt;i
                  class="fa fa-plus"&gt;&lt;/i&gt;Generate and download invoice&lt;/span&gt;&lt;/button&gt;
  </code></pre>
  
  <p>and my js controller function looks like :</p>
  
  <pre><code>            $scope.generateAndDownloadPdf = function(){
               //getting download url from api
              api.events.invoice.download($stateParams.eventId, $stateParams.speakerId).then(function(data){
                  console.log(data)
                  //give url to user
  
              });
  
          }
  </code></pre>
  
  <p>I know that once I have the download url I can use this html code, but  was wondering if I can do all in one click for the user.</p>
  
  <pre><code>            &lt;a
             target="_self"
             href="download.url"
             download="file.pdf"&gt;
              &lt;button type="button" class="btn btn-success btn-block" ng-click=""&gt;&lt;i
                      class="fa fa-plus"&gt;&lt;/i&gt;Download Invoice&lt;/span&gt;&lt;/button&gt;
          &lt;/a&gt;
  </code></pre>
  
  <p>Thank you all!</p>