Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The key is you should use <a href="http://docs.angularjs.org/api/ng.%24interpolate">$interpolate</a> instead of <a href="http://docs.angularjs.org/api/ng.%24compile">$compile</a></p> <blockquote> <p><strong>Description of $interpolate</strong></p> <p>Compiles a string with markup into an interpolation function. This service is used by the HTML $compile service for data binding. See $interpolateProvider for configuring the interpolation markup.</p> </blockquote> <p>When you use $complie, it will turn your string into element. </p> <blockquote> <p><strong>Description of $compile</strong></p> <p>Compiles a piece of HTML string or DOM <strong>into a template</strong> and produces a template function, which can then be used to link scope and the template together.</p> </blockquote> <p>(To be honest, I don't really understand the description until trying it out.)</p> <p>Here is the working <a href="http://plnkr.co/edit/3rtp1v?p=preview">plunk</a></p> <pre><code>app.controller('MainCtrl', function($scope) { $scope.cdnPath = "//path/to/cdn/"; $scope.version = "1.0"; }); app.directive('snippet', ['$timeout', '$interpolate', function($timeout, $interpolate) { return { restrict: 'E', template:'&lt;pre&gt;&lt;code ng-transclude&gt;&lt;/code&gt;&lt;/pre&gt;', replace:true, transclude:true, link:function(scope, elm, attrs){ var tmp = $interpolate(elm.find('code').text())(scope); $timeout(function() { elm.find('code').html(hljs.highlightAuto(tmp).value); }, 0); } }; }]); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload