Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs: How to stream http response to new window?

Tags:

angularjs

How can I use the angularjs $http service to post a request to the server and stream the result to a new browser window?

My service generates and streams back a pdf report which I'd like to open in a new browser window. So far I've been using $http to post requests which returned json data. I could use this to update the model. That works fine. But now I don't want to extract data from the response, just display in another window. Perhaps I should be using a lower level service rather than the data exchange pattern I've been using?

$http(httpPostConfig).success(
    function(data, status, headers, config) {
        ...
    }
).error(

    function(data, status, headers, config) {
        ...
    }
);
like image 236
Glenn Avatar asked Mar 11 '13 18:03

Glenn


1 Answers

Have your server return a unique identifier of the generated PDF and than use $window service to open a new window with it's url pointing to a server-side endpoint which returns PDf based on unique identifier (e.g. $window.open('/pdf/6234556'));

like image 144
Stewie Avatar answered Oct 03 '22 01:10

Stewie