I'm running into an issue with obtaining the compiled html of a page in AngularJS. Below is the code snippet that demonstrates this problem:
JavaScript:
<script src="http://code.angularjs.org/1.2.0rc1/angular.min.js"></script>
<script>
var app = angular.module('main', []);
app.directive("compile", ['$compile', function ($compile) {
return {
link: function(scope, elem, attr){
var compiledHTML = $compile(elem.contents())(scope);
console.log(compiledHTML);
var returnString = '';
for(i=0; i<compiledHTML.length; i++)
returnString += compiledHTML[i].outerHTML;
console.log(returnString);
}
};
}]);
</script>
HTML:
<html ng-app="main" compile>
<body>
{{3 + 4}}
</body>
</html>
The issue I am facing is when I use the first console.log(), it displays the compiled data as 7 in the outerHTML property. However, when I try to output all the .outerHTML, it only shows the uncompiled version, {{3 + 4}}