javascript - Getting Compiled HTML from AngularJS -


i'm having trouble getting compiled html of page in angularjs. here's 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 strange in first console.log(), shows compiled data, 7, in outerhtml property, when output .outerhtml, shows uncompiled version, {{3 + 4}}

looks timing issue. waiting process compiledhtml did trick.

$timeout(function(){     var returnstring = '';     for(i=0; i<compiledhtml.length; i++)         returnstring += compiledhtml[i].outerhtml;      console.log(returnstring); },0); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -