Home » Javascript » print div is not working in angularjs

print div is not working in angularjs

Posted by: admin October 29, 2018 Leave a comment


I have two text box. If I enter any value in textbox afterthat if I click print the entered value is not coming on the print page. Only empty text box is coming. Please help me how can I resolve this issue.


<!DOCTYPE html>

  <meta charset="utf-8" />
  <title>AngularJS Print Directive of html templates </title>
  <link rel="stylesheet" href="style.css" />
  <script src="https://code.angularjs.org/1.4.1/angular.js"></script>
    var app = angular.module('myApp', []);

    app.controller('myCtrl', function($scope) {
      $scope.printToCart = function(printSectionId) {
        var innerContents = document.getElementById(printSectionId).innerHTML;
        var popupWinindow = window.open('', '_blank', 'width=600,height=700,scrollbars=no,menubar=no,toolbar=no,location=no,status=no,titlebar=no');
        popupWinindow.document.write('<html><head><link rel="stylesheet" type="text/css" href="style.css" /></head><body onload="window.print()">' + innerContents + '</html>');

<body id="printSectionId" ng-app="myApp">
  <div ng-controller="myCtrl">
    <h1>AngularJS Print html templates</h1>
    <form novalidate>
      First Name:
      <input type="text" ng-model="firstName" class="tb8">
      <br> Last Name:
      <input type="text" ng-model="lastName" class="tb8">
      <button ng-click="Submit()" class="button">Submit</button>
      <button ng-click="printToCart('printSectionId')" class="button">Print</button>
    <br/><a href="http://www.code-sample.com/2015/07/angularjs-2-forms-validation.html" target="_blank">More About AngularJS Print...</a></div>