1

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.

plunkr

<!DOCTYPE html>
<html>

<head>
  <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>
  <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.open();
        popupWinindow.document.write('<html><head><link rel="stylesheet" type="text/css" href="style.css" /></head><body onload="window.print()">' + innerContents + '</html>');
        popupWinindow.document.close();
      }
    });
  </script>
</head>

<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>
      <br> Last Name:
      <input type="text" ng-model="lastName" class="tb8">
      <br>
      <br>
      <button ng-click="Submit()" class="button">Submit</button>
      <button ng-click="printToCart('printSectionId')" class="button">Print</button>
    </form>
  </div>
  <div>
    <br/>
    <br/><a href="http://www.code-sample.com/2015/07/angularjs-2-forms-validation.html" target="_blank">More About AngularJS Print...</a></div>
</body>

</html>

3
  • innerHTML does not read form values Commented May 22, 2018 at 13:11
  • verify that your are allwoing popups in your browser, on the other hand here in won't reproduce because of sandboxed frame show 'allwo-popups' permission is not set. Commented May 22, 2018 at 13:16
  • It has setted. I enabled allowd popup permission. Now also its not working. Commented May 22, 2018 at 13:27

1 Answer 1

3

This is a simple solution to this, just add a value field to the tag. Hope it works.

First Name:
  <input type="text" ng-model="firstName" class="tb8" value={{firstName}}>
  <br>
  <br> Last Name:
  <input type="text" ng-model="lastName" class="tb8" value={{lastName}}>
  <br>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.