是否可以$編譯HTML文檔, - 不是像$compile
那樣的元素期望?
問題我試圖解決:我在外部.html文件打印形式,我想包括該行:<link rel="stylesheet" type="text/css" href="styles.css">
現在,我不能這樣做,因爲$compile
期待element
參數,哪一個是DOM元素並且不能包含(或簡單地忽略到樣式表的鏈接)。
模板我有:
<div>
<span ng-bind="model.tasks.count"></span>
</div>
模板,我想有(我的主要目標 - 提取樣式成單獨的文件):我的代碼
<html>
<head>
<link href="/app/style.css" rel="stylesheet">
</head>
<body>
<div>
<span ng-bind="model.tasks.count"></span>
</div>
</body>
</html>
實施例:
return $q.all([ getTemplate(), getScope() ]).then(
function(msg) {
var element = angular.element(msg[0]); // Now it's DOM element
$compile(element)(msg[1]); // If i pass HTML document, element goes undefined
openWindow(element);
});
and openWindow:
function openWindow(element) {
$timeout(function() {
var html = element.html();
var _w = window.open();
_w.document.body.innerHTML = html; // Here i'd like to write complete HTML doc
_w.print();
});
}