Hi Edwin, Paul,
I wanted to trigger downloads from angular also, here is how I achieved it
but I'm not sure if this is what ye are looking for
$http({
method: 'GET',
url: 'http://localhost/products/excel/'
}).success(function(data, status, headers, config) {
var element = angular.element('<a/>');
element.attr({
href: 'data:attachment/excel;charset=utf-8,' +
encodeURI(data),
target: '_self',
download: 'products.xls'
})[0].click();
});
Regards
Jonathan
On Tuesday, August 6, 2013 10:53:58 AM UTC+1,
[email protected] wrote:
>
> Hi Edwin,
>
> I'd be interested to know if you found a way to do this. I have the same
> problem. I need to trigger the download from angular code / ajax rather
> than a form postback, for reasons that are not of interest here. Is there a
> way of doing this?
>
> Paul Taylor
>
> On Wednesday, 9 January 2013 13:57:41 UTC, Edwin Beltran wrote:
>>
>> hi mark... in my case I have to. I am using Angular for everything and I
>> do not want to do things outside of the scope of Angular (non-scripted). I
>> did a workaround. my issue happened when I wanted to handle two response in
>> the same call. I wanted to handle a call to my api: "api/print/:id" and the
>> response may contain a "no print available" or the file... but, I couldn't
>> find a way to trigger the download in a XHR response. but my workaround is
>> that the XHR response generate a token, and then I do a regular browser
>> request (GET) with the token directly (non-scripted) with
>> "window.open('api/print?token=:token')" and the browser by itself read the
>> HttpResponseMessage and detect the attachment and triggers the download. I
>> thought that may be a way to trigger the download directly from the XHR
>> response.
>>
>> for example... in Chrome in the network tab in the dev console, I can see
>> the XHR request to "api/print/:id", and I see the file in the response, and
>> when I right click in the response and select open in a new tab, it
>> triggers the download... funny!!! but didnt find the way to trigger it
>> using angular, or JS... //_e
>>
>> --
>> Saludos,
>>
>> Edwin Beltrán
>> Mobile: (787) 996-1428
>>
>>
>> On Wed, Jan 9, 2013 at 7:12 AM, mark prades <[email protected]> wrote:
>>
>>> i dont think you should use ajax for that , you can use a regular form
>>> if you need a post request then serve the file as an attachment with
>>> content disposition, What's effective with non scripted html files stays
>>> effective in a scripted context , you should try to re-invent the wheel.
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.