我有一个使用AngularJS的HTML页面,我想从中打印出一个div。是否有一种Angular方法可以实现呢?还是只能使用下面经典的JavaScript方式:
<script language="javascript" type="text/javascript">
function printDiv(divID) {
//Get the HTML of div
var divElements = document.getElementById(divID).innerHTML;
//Get the HTML of whole page
var oldPage = document.body.innerHTML;
//Reset the page's HTML with div's HTML only
document.body.innerHTML =
"<html><head><title></title></head><body>" +
divElements + "</body>";
//Print Page
window.print();
//Restore orignal HTML
document.body.innerHTML = oldPage;
}
</script>
如果在AngularJS中没有类似的功能,您能否推荐一种方式来实现它,而不使用JavaScript函数(例如:doc.getElementById()),接近于AngularJS方式的方法? 谢谢。
angular.element
。 - tymeJV