[英]AngularJS : Write HTML Output to textfile
I'm working on an AngularJS 1.5 project with PhoneGap. 我正在使用PhoneGap进行AngularJS 1.5项目。 Now I would like to write the HTML output to a textfile.
现在,我想将HTML输出写入文本文件。
I was trying to use the innerHTML function, but this returns the wrong output, example this return: 我试图使用innerHTML函数,但这会返回错误的输出,例如以下返回:
<html>
<body>Hi {{ Name }}</body>
</html>
What I really want to save: 我真正要保存的是:
<html>
<body>Hi Developer</body>
</html>
Does someone has the solution? 有人有解决方案吗? Thanks!
谢谢!
This is going to be a bit more complicated than what it seems at first glance. 这将比乍看之下要复杂一些。 Angular does not have some sort of output buffering you simply can get a hold of.
Angular没有某种输出缓冲,您可以简单地掌握一下。 Your best bet will be to to save the rendered markup using your browser.
最好的选择是使用浏览器保存渲染的标记。 In Firefox you can use
View Source » View Generated Source
. 在Firefox中,您可以使用
View Source » View Generated Source
。 In Chrome you find a similar option under the tools menu. 在Chrome中,您可以在工具菜单下找到类似的选项。
Or if you want to go down the code road, here is a response from one of the Angular devs, Misko Hevery : 或者,如果您想走代码之路,这是Angular开发人员之一Misko Hevery的回应 :
We have not done this, but if you feel up to it here is what you can try
我们尚未做到这一点,但是如果您愿意,可以尝试以下方法
- get node.js running
让node.js运行
- install of the many DOM implementations for node
为节点安装许多DOM实现
- Get your angular page running inside the node.js.
使您的Angular页面在node.js中运行。
- Get a hold of the $browser service and call
notifyWhenNoOutstandingRequests()
this will tell you when the page finished rendering持有$ browser服务并调用
notifyWhenNoOutstandingRequests()
它将告诉您页面何时完成渲染- Do document.html() to get rendered HTML
执行document.html()以获取呈现的HTML
[...]
[...]
If you're actually using angular then you should be able to use innerHTML
after the binding is done. 如果您实际上使用的是angular,则绑定完成后应该可以使用
innerHTML
。 ( fiddle ) ( 小提琴 )
<div ng:controller="CombinedCtrl" id="combined">
X: {{x}}, Y: {{y}}
<button ng-click="showHtml()">Show HTML</button>
</div>
JS: JS:
$scope.showHtml = function() {
alert('HTML IS:\r\n' + document.getElementById('combined').innerHTML);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.