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 -

django - CSRF verification failed. Request aborted. CSRF cookie not set -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -