簡體   English   中英

print div在angularjs中不起作用

[英]print div is not working in angularjs

我有兩個文本框。 如果我在文本框中輸入任何值,如果我單擊打印,則輸入的值不會出現在打印頁面上。 只有空文本框才會出現。 請幫助我如何解決此問題。

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> 

這是一個簡單的解決方案,只需在標記中添加一個值字段即可。 希望它有效。

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM