Javascript – Calling $window.print() in angularjs causes the print preview to show a blank page

angularjscsshtmljavascriptprinting

I have a very strange problem where, when I call $window.print in angularjs, all I see is the date on the top left, page name on the top, page number on the bottom right, and the url on the bottom left. However, there is no other content on the page, which is very weird since the regular page has plenty of content.

I guess of mine is that this has to do with an ng-view I have on the page, but I'm not too sure. I would add a print style sheet, but my problem is more on the side that there is no content to style to begin with. Any ideas?

Best Answer

Try to use(don't forget to inject service $timeout):

$timeout(function() {
    $window.print();
})

I think your problem in that angular haven't finishes the digest cycle and updates the DOM.