angularjs - Appending a tag with interpolation using JavaScript in Angular -


i've got testing routine creates div tag, appends body, , sets innerhtml property to:

<p>{{testvar}}</p>

all javascript, so:

var created = document.createelement('h1');  var elem = document.body.appendchild(created); elem.innerhtml='<p>{{testvar}}</p>'; 

it shows on page, double curly brackets , all. correct way dynamically add single element page interpolation recognized?

you have compile html against current scope, can use directive:

app.directive("mydynamichtml", ["$compile", function($compile) {     return {         restrict: "a",         link: function(scope, elem, attrs) {             var compiledhtml = $compile("<h1><p>{{testvar}}</p></h1>")(scope);             document.body.appendchild(compiledhtml);         }     } }]); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

c# - How do I get the Nth largest element from a list with duplicates, using LINQ? -

jsp - "Sending a redirect is forbidden after the response has been committed" in sendRedirect -