I'm currently having an issue trying to print a report. We are using an Angularjs solution. We display the report for the user, and when they hit print we have the template switch. Then we call window.print() (which normally stops javascript code execution). Then after printing we swap the template back to the display.
This currently works in chrome and safari on a mac. However when we use an Ipad/Iphone the templates swaps, swaps back and then print appears and the print preview is incorrect.
Searching for answers I found: people talking about using var mql = window.matchMedia('print') and then using add.listener(function) and doing the swap in the function. The below code I was able to get Ipad/Iphone to swap to the correct template and print however it does not swap back.
VcrReportController.prototype.printReport = function () {
var vm = this;
var mql = window.matchMedia('print');
var printHandler = function(mql){
if (mql.matches){
console.log('print');
vm.template = 'displayTemplate'
}
else{
console.log('not print');
}
}
function changeTemplate() {
var deferred = vm.$q.defer();
vm.template = 'printTemplate';
vm.$timeout(function () {
deferred.resolve(true);
},250);
return deferred.promise;
}
changeTemplate()
.then(function (response) {
mql.addListener(printHandler);
vm.$window.print();
});
Not 100% sure about the listener stuff. Any help or other solutions people might have used to deal with this kind of situation would be great.
Thanks,