When you click a button to print a report, it should consult with AngularJS some information in the database and then execute the command for printing (% with%) after the page is already loaded information.
When I try to do this, it goes into the print preview before the page is fully loaded. It is true that simply waiting for the same print load and click could resolve but, in my case, automatic printing would be much more interesting.
I need the command $window.print()
to run only after the appropriate information is already on the page.
How do I do this check?
---- Edited:
There is a specific service where you query the data of a particular employee and a check relative ( $window.print()
) to the query. This code is inside the corresponding screen specific controller.
funcionarioService.getListagem(self.funcionarioId, function (r) {
if (r.sucesso) {
self.funcionario = r.conteudo;
// Estranhamente desta forma soluciona meu problema
// Acredito que este é executado após o carregamento total da página,
// mas não encontrei nenhuma confirmação a respeito.
window.setTimeout(function() {
window.print()
}, 1);
}
});
---- Edited [2]:
This link talks about why this proposed solution works but the explanation was not very clear.