【发布时间】:2018-01-28 14:56:49
【问题描述】:
我正在创建隐藏 iframe 以打印一些数据,但我的代码无法正常工作,我想通过使用 angular 范围变量在该 iframe 中显示一些数据,下面是我的代码。
// print attached contract documnet
function print(imageData) {
var hiddenFrame = $('<iframe style="display: none"></iframe>').appendTo('body')[0];
hiddenFrame.contentWindow.printAndRemove = function () {
hiddenFrame.contentWindow.print();
$(hiddenFrame).remove();
};
$scope.testObj = 'testing';
var element = $compile('<div> {{testObj}} </div>')($scope);
// var element = $compile($('<div> <img ng-src="{{ vm.contractDetails.contractAttachment.imageSRC }}" class="img-thumbnail img-responsive img-height " style="height:500px;cursor:pointer;" /> </div>'))(printScope);
var htmlDocument = "<!doctype html>" +
"<html>" +
'<body onload="printAndRemove();">' +
element.html() +
'</body>' +
"</html>";
var doc = hiddenFrame.contentWindow.document.open("text/html", "replace");
doc.write(htmlDocument);
doc.close();
}
$scope.testObj 绑定不正确。
【问题讨论】:
标签: javascript html angularjs iframe