Search code examples
ember.jsember-cli

Initiate download and execute action?


I've got a link which is supposed to execute an action and initiate a download. However as soon as an {{action}} ist set the hrefattribute is suppressed.

<a {{bind-attr href=download.filepath}} {{ action "incDownload"  }}>
    {{ download.name }}
</a>

How can I make this work?


Solution

  • Pass the filepath as a parameter to the action instead and initiate the download in the action.

    <a {{ action "incDownload" download.filepath }}>
        {{ download.name }}
    </a>
    

    and then your action will have access to the filepath:

    incDownload: function(filepath){
       // do stuff
    
       // peform the download
       window.location = filepath;
    }