title: Dynamic Syntax Highlighting with AngularJS and Highlight.js
body: <p>I am building a site that illustrates common application vulnerabilities such as SQL Injection.  I am using <strong>AngularJS</strong> and <strong>highlight.js</strong> to create interactive examples.  </p>
  
  <p><em>How can I make both AngularJS and highlight.js update my code snippets?</em></p>
  
  <h1>Example</h1>
  
  <p><a href="http://jsfiddle.net/Good_man/Lv56y2yy/6/">This Fiddle</a> demonstrates how entering <code>' OR 1=1 --</code> in the Email field could change the intended behavior of the query if the user's input is not validated or sanitized. </p>
  
  <pre><code>SELECT * FROM dbo.Users WHERE Email='{{email}}' AND Password='{{password}}'  
  </code></pre>
  
  <p>When a user enters an email address and password, Angular updates the query. However, syntax highlighting does not update.</p>
  
  <pre><code>SELECT * FROM dbo.Users WHERE Email='user@domain.com' AND Password=''
  </code></pre>
  
  <p>I tried re-initializing hljs, but when I do angular stops updating the query.</p>
  
  <pre><code>hljs.initHighlighting.called = false;
  hljs.initHighlighting();
  </code></pre>
  
  <h2>Application</h2>
  
  <pre><code>&lt;script&gt;
      var app = angular.module("app", ['hljs']);
      app.controller("controller", function($scope) {
          $scope.email = "user@domain.com";
          $scope.password = "";
      })
  &lt;/script&gt;
  &lt;div ng-app="app" ng-controller="controller"&gt;
      &lt;div&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-sm-4"&gt;Email
                  &lt;input type="text" class="form-control" ng-model="email"&gt;
              &lt;/div&gt;
              &lt;div class="col-sm-4"&gt;Password
                  &lt;input type="text" class="form-control" ng-model="password"&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;br&gt;
          &lt;div hljs include="'compile-me'" compile="true" language="sql"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;script type="text/ng-template" id="compile-me"&gt;
          SELECT * FROM dbo.Users WHERE Email = '{{email}}'
          AND Password = '{{password}}'
      &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>