简体   繁体   English

如何强制页面等待Angular。 html2pdf.it无法呈现AngularJS

[英]How force page to wait for Angular. html2pdf.it does not render AngularJS

I want to convert HTML pages to PDF. 我想将HTML页面转换为PDF。 html2pdf.it seems a good tool, as it's open source and I can install it in my own server. html2pdf.it似乎是一个很好的工具,因为它是开源的 ,我可以将其安装在自己的服务器中。

Only is needed to add the url to the path: 仅需要将URL添加到路径:

http://www.html2pdf.it/?url= http://www.html2pdf.it/?url=

I made two simple pages. 我做了两个简单的页面。 One using angularjs and other with just JavaScript. 一种使用angularjs,另一种仅使用JavaScript。 On first one Angular is not render, I see {{text}} . 在第一个未渲染Angular的地方,我看到{{text}} This is weird because angularjs.org is converted to PDF correctly. 这很奇怪,因为angularjs.org已正确转换为PDF。 JS version works too. JS版本也可以。

How do I force it to wait to angular to finish? 我如何强迫它等待成角度地完成?

Code: 码:

<html lang="en">
<head>
    <title>Minimum AngularJS page</title>
    <meta charset="UTF-8">
</head>
<body ng-app="demoApp">
    <div ng-controller="MainCtrl">
  <h1>Hello World!</h1>
          <p>{{text}}</p>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
    <script>
        angular
            .module('demoApp', [])
            .controller('MainCtrl', function($scope){
                $scope.text = "If you see this means angularjs is working";
            });
    </script>
</body>
</html>

EDIT April 8 2016: 编辑2016年4月8日:

I doesn't work neither with async calls eg; 我也不使用异步调用,例如; setTimeout()

I would recommend that you try to use the ng-bind-html to render the html from a scope variable. 我建议您尝试使用ng-bind-html从作用域变量中呈现html。 something like the attached snippet. 类似于所附的代码段。 You will have to include the angular-sanitize.js and also include a module ngSanitize as done in the code snippet. 您将必须包含angular-sanitize.js,还必须包括ngSanitize模块,如代码片段所示。

 <html lang="en"> <head> <title>Minimum AngularJS page</title> <meta charset="UTF-8"> </head> <body ng-app="demoApp"> <div ng-controller="MainCtrl"> <h1>Hello World!</h1> <p ng-bind-html="text"></p> </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-sanitize.js"></script> <script> angular .module('demoApp', ['ngSanitize']) .controller('MainCtrl', function($scope){ $scope.text = "If you see this means angularjs is working"; }); </script> </body> </html> 

Thanks, Paras 谢谢,帕拉斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM