angularjs - Angular, get a template and populate it in a service -
i've got printing service, has function gets passed template url , data template.
i need somehow populate template data provided , open in new window. here's pseudo code idea:
printwindow.printmodal = function(data, template) { get(template).success(function(data) { populatedtemplate = populate(template) var mywindow = window.open('', '_blank'); mywindow.document.write('<html><head>'); mywindow.document.write('</head><body>'); mywindow.document.write(populatedtemplate); mywindow.document.write('</body></html>'); }); return true;
};
how achieve this?
figured out:
$http.get(template).success(function(data) { var templateelement = angular.element('<div></div>'); templateelement.append(data); var clonedelement = $compile(templateelement)($scope.data); $timeout(function() { var printwindow = window.open('', '_blank'); printwindow.document.write('<html><head>'); printwindow.document.write('</head><body>'); printwindow.document.write(clonedelement.html()); printwindow.document.write('</body></html>'); }); });
Comments
Post a Comment