I'm having trouble getting the compiled html of a page in AngularJS. Here's the code:
JS:
<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>
What is strange is in the first console.log(), it shows the compiled data, 7, in the outerHTML property, but when I output all the .outerHTML, it shows the uncompiled version, {{3 + 4}}
console.log
is the same as stackoverflow.com/a/18597550/1529630 – Oriol Sep 3 '13 at 17:57