The code below tries to copy a certain part of the the page, basically the form without the buttons into a new document. Once this is done, the aim is to print() it.
The problem is that the .write() is not capturing the content/values of the form only the html tags. The fields are copied and but are empty.
I wonder is that because i'm using the angular inherit $scope and ng-model functionality which the document.write cannot handle?!
The form that i want to print has this tag
<form name="ticketForm" id="printForm" class="form-horizontal" novalidate>
and the button to initiate the call is
<button type="button"
class="btn btn-primary"
ng-click="printElem()"
>
Print
</button>
The js files . Mind you i had to do all that shenanigans of adding the header and other elements piece by piece since i want to remove the table, buttons among other things. I only want to print the form but still remain the CSS.
$scope.printElem = function(){
$log.info("i'm here");
//Popup($(elem).html().print());
var elem = document.getElementById("printForm");
$log.info(elem);
var pwindow= window.open('', 'printForm', 'height=800,width=600');
pwindow.document.write('<html ng-app="HelpDeskApp0" class="ng-scope"><head><style type="text/css">@charset "UTF-8";[ng\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide:not(.ng-hide-animate){display:none !important;}ng\:form{display:block;}</style>');
//window.print();
pwindow.document.write('<link href="css/bootstrap.css" rel="stylesheet" type="text/css">' +
'<link href="css/ashraf.css" rel="stylesheet" type="text/css">' +
'<link href="css/json-tree.css" rel="stylesheet" type="text/css">' +
'<link href="css/loading-bar.css" rel="stylesheet" type="text/css">' +
'<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css">' +
'<link href="css/dx.common.css" rel="stylesheet" type="text/css">' +
'<link href="css/dx.light.css" rel="stylesheet" type="text/css">');
pwindow.document.write('<script src="lib/jquery-2.1.4.js"></script>' +
'<script src="lib/angular.min.js"></script>'+
'<script src="lib/angular-sanitize.js"></script>'+
'<script src="lib/angular-resource.js"></script>'+
'<script src="lib/globalize.min.js"></script>'+
'<script src="lib/ui-bootstrap-tpls.js"></script>'+
'<script src="lib/angular-route.js"></script>'+
'<script src="lib/bootstrap.js"></script>'+
'<script src="lib/dx.all.js"></script>'+
'<script src="js/app.js"></script>'+
'<script src="js/controllers.js"></script>'+
'<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">'+
'<meta name="apple-mobile-web-app-capable" content="yes">'+
'<meta name="apple-mobile-web-app-status-bar-style" content="black"> </head>');
pwindow.document.write('<body><nav class="panel panel-primary"> <!-- navbar navbar-default-->'+
'<div class="container-fluid">'+
'<!-- Brand and toggle get grouped for better mobile display -->'+
'<div class="menubar" role="navigation">'+
'<div class="">'+
'<div class="menubar-content-left">'+
'<a><img src="images/mgpi.png" height="50" width="50"> <b style="color: #428bca">MGPI - Beta Version</b></a>'+
'</div> '+
'</div>'+
'</div>'+
'<!-- Collect the nav links, forms, and other content for toggling -->'+
'<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">'+
' <ul class="nav navbar-nav">'+
'<li><a href="#/home">Help Desk</a></li>'+
'</ul> '+
'</div><!-- /.navbar-collapse -->'+
'</div><!-- /.container-fluid -->'+
'</nav>'+
'<!-- ngView: --><div ng-view="" class="container-fluid ng-scope"><div ng-controller="homeController" class="ng-scope">'+
'<div class="container bs-docs-container"> '+
'<div class="row"> '+
'<div class="row margin-top">'+
'<br>'+
'</div>'+
'<div class="row margin-top margin-left">'+
'<div class="col-sm-12 top-buffer">');
pwindow.document.write('<div class="well well-lg" style="height: 250vh; background-color:#ADD8E6">'+
elem.innerHTML + '<br></div> </div></div></div> </div></div></div></body></html>');
$log.info(pwindow.document);
//pwindow.print();
//pwindow.close();
};
I TRIED multiple ways with elem.innerHTML, elem.value etc but none capture the value of the fields. The form is written and thus printed with empty values although the original form has values. Here is a screen shot. Any ideas why? and thanks!
