title: AngularJs - Get a string from compiled HTML/Variable
body: <p>I try to get a string that i can edit later (with Textangular or saved it in DB) from a template coming from server (in DB).</p>
  
  <pre><code>    TemplateMailService.get($scope.type, function (data, status) {
  
  
              $scope.template = data.template;
              // data.template.content = '&lt;p&gt;Hi &lt;span ng-if="client.email == 'email@email.com'"&gt;{{email}}&lt;/span&gt;!&lt;/p&gt;'
              $timeout(function () {
  
                  data.template.content = $compile(data.template.content)($scope);
  
                  $log.debug('$scope.mail.content : ', $scope.mail.content);
                  $log.debug('data.template.content : ', angular.element(data.template.content));
                  // is compiled correctly. I can see the ng-if apply and the {{variable}} compiled
                  var string = '';
                  string += data.template.content[0].innerHTML;
  
                  console.log(string);
                  // =&gt; ng-if not apply and {{variable}} not compiled...
  
                  $scope.mail.content = string;
              }, 0);
  
      })
  </code></pre>
  
  <p>I want to be able to save the compiled template (with all the ng-xx and {{ variables}} applied in a string to edit it in textangular.</p>
  
  <p>I know i should be doing this with a directive but i dont get how i can return the compiled template in a string.</p>
  
  <p>What i'm missing here ?</p>
  
  <p>Thanks.</p>